5 int ventidoublechecksha1 = 1;
8 vtfcallrpc(VtConn *z, VtFcall *ou, VtFcall *in)
15 if((p = _vtrpc(z, p, ou)) == nil)
17 if(vtfcallunpack(in, p) < 0){
22 fprint(2, "%s <- %F\n", argv0, in);
23 if(in->msgtype == VtRerror){
29 if(in->msgtype != ou->msgtype+1){
30 werrstr("type mismatch: sent %c%d got %c%d",
31 "TR"[ou->msgtype&1], ou->msgtype>>1,
32 "TR"[in->msgtype&1], in->msgtype>>1);
46 memset(&tx, 0, sizeof tx);
47 tx.msgtype = VtThello;
48 tx.version = z->version;
52 if(vtfcallrpc(z, &tx, &rx) < 0)
61 vtreadpacket(VtConn *z, uchar score[VtScoreSize], uint type, int n)
65 if(memcmp(score, vtzeroscore, VtScoreSize) == 0)
69 werrstr("not connected");
73 if(z->version[1] == '2' && n >= (1<<16)) {
74 werrstr("read count too large for protocol");
77 memset(&tx, 0, sizeof tx);
81 memmove(tx.score, score, VtScoreSize);
82 if(vtfcallrpc(z, &tx, &rx) < 0)
84 if(packetsize(rx.data) > n){
85 werrstr("read returned too much data");
89 if(ventidoublechecksha1){
90 packetsha1(rx.data, tx.score);
91 if(memcmp(score, tx.score, VtScoreSize) != 0){
92 werrstr("read asked for %V got %V", score, tx.score);
101 vtread(VtConn *z, uchar score[VtScoreSize], uint type, uchar *buf, int n)
106 if((p = vtreadpacket(z, score, type, n)) == nil)
109 if(packetconsume(p, buf, nn) < 0)
116 vtwritepacket(VtConn *z, uchar score[VtScoreSize], uint type, Packet *p)
120 if(packetsize(p) == 0){
121 memmove(score, vtzeroscore, VtScoreSize);
124 tx.msgtype = VtTwrite;
127 if(ventidoublechecksha1)
128 packetsha1(p, score);
129 if(vtfcallrpc(z, &tx, &rx) < 0)
131 if(ventidoublechecksha1){
132 if(memcmp(score, rx.score, VtScoreSize) != 0){
133 werrstr("sha1 hash mismatch: want %V got %V", score, rx.score);
137 memmove(score, rx.score, VtScoreSize);
142 vtwrite(VtConn *z, uchar score[VtScoreSize], uint type, uchar *buf, int n)
147 p = packetforeign(buf, n, 0, nil);
148 nn = vtwritepacket(z, score, type, p);
158 tx.msgtype = VtTsync;
159 return vtfcallrpc(z, &tx, &rx);
167 tx.msgtype = VtTping;
168 return vtfcallrpc(z, &tx, &rx);
186 tx.msgtype = VtTgoodbye;
187 vtfcallrpc(z, &tx, &rx); /* always fails: no VtRgoodbye */