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)
68 if(z->version[1] == '2' && n >= (1<<16)) {
69 werrstr("read count too large for protocol");
72 memset(&tx, 0, sizeof tx);
76 memmove(tx.score, score, VtScoreSize);
77 if(vtfcallrpc(z, &tx, &rx) < 0)
79 if(packetsize(rx.data) > n){
80 werrstr("read returned too much data");
84 if(ventidoublechecksha1){
85 packetsha1(rx.data, tx.score);
86 if(memcmp(score, tx.score, VtScoreSize) != 0){
87 werrstr("read asked for %V got %V", score, tx.score);
96 vtread(VtConn *z, uchar score[VtScoreSize], uint type, uchar *buf, int n)
101 if((p = vtreadpacket(z, score, type, n)) == nil)
104 if(packetconsume(p, buf, nn) < 0)
111 vtwritepacket(VtConn *z, uchar score[VtScoreSize], uint type, Packet *p)
115 if(packetsize(p) == 0){
116 memmove(score, vtzeroscore, VtScoreSize);
119 tx.msgtype = VtTwrite;
122 if(ventidoublechecksha1)
123 packetsha1(p, score);
124 if(vtfcallrpc(z, &tx, &rx) < 0)
126 if(ventidoublechecksha1){
127 if(memcmp(score, rx.score, VtScoreSize) != 0){
128 werrstr("sha1 hash mismatch: want %V got %V", score, rx.score);
132 memmove(score, rx.score, VtScoreSize);
137 vtwrite(VtConn *z, uchar score[VtScoreSize], uint type, uchar *buf, int n)
142 p = packetforeign(buf, n, 0, nil);
143 nn = vtwritepacket(z, score, type, p);
153 tx.msgtype = VtTsync;
154 return vtfcallrpc(z, &tx, &rx);
162 tx.msgtype = VtTping;
163 return vtfcallrpc(z, &tx, &rx);
181 tx.msgtype = VtTgoodbye;
182 vtfcallrpc(z, &tx, &rx); /* always fails: no VtRgoodbye */