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){
24 werrstr("%s", in->error);
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 memset(&tx, 0, sizeof tx);
72 memmove(tx.score, score, VtScoreSize);
73 if(vtfcallrpc(z, &tx, &rx) < 0)
75 if(packetsize(rx.data) > n){
76 werrstr("read returned too much data");
80 if(ventidoublechecksha1){
81 packetsha1(rx.data, tx.score);
82 if(memcmp(score, tx.score, VtScoreSize) != 0){
83 werrstr("read asked for %V got %V", score, tx.score);
92 vtread(VtConn *z, uchar score[VtScoreSize], uint type, uchar *buf, int n)
97 if((p = vtreadpacket(z, score, type, n)) == nil)
100 if(packetconsume(p, buf, nn) < 0)
107 vtwritepacket(VtConn *z, uchar score[VtScoreSize], uint type, Packet *p)
111 if(packetsize(p) == 0){
112 memmove(score, vtzeroscore, VtScoreSize);
115 tx.msgtype = VtTwrite;
118 if(ventidoublechecksha1)
119 packetsha1(p, score);
120 if(vtfcallrpc(z, &tx, &rx) < 0)
122 if(ventidoublechecksha1){
123 if(memcmp(score, rx.score, VtScoreSize) != 0){
124 werrstr("sha1 hash mismatch: want %V got %V", score, rx.score);
128 memmove(score, rx.score, VtScoreSize);
133 vtwrite(VtConn *z, uchar score[VtScoreSize], uint type, uchar *buf, int n)
138 p = packetforeign(buf, n, 0, nil);
139 nn = vtwritepacket(z, score, type, p);
149 tx.msgtype = VtTsync;
150 return vtfcallrpc(z, &tx, &rx);
158 tx.msgtype = VtTping;
159 return vtfcallrpc(z, &tx, &rx);
177 tx.msgtype = VtTgoodbye;
178 vtfcallrpc(z, &tx, &rx); /* always fails: no VtRgoodbye */