5 int ventidoublechecksha1 = 1;
8 vtfcallrpc(VtConn *z, VtFcall *ou, VtFcall *in)
13 fprint(2, "%s -> %F\n", argv0, ou);
17 if((p = vtrpc(z, p)) == nil)
19 if(vtfcallunpack(in, p) < 0){
24 fprint(2, "%s <- %F\n", argv0, in);
25 if(in->type == VtRerror){
31 if(in->type != ou->type+1){
32 werrstr("type mismatch: sent %c%d got %c%d",
33 "TR"[ou->type&1], ou->type>>1,
34 "TR"[in->type&1], in->type>>1);
48 memset(&tx, 0, sizeof tx);
50 tx.version = z->version;
54 if(vtfcallrpc(z, &tx, &rx) < 0)
63 vtreadpacket(VtConn *z, uchar score[VtScoreSize], uint type, int n)
67 if(memcmp(score, vtzeroscore, VtScoreSize) == 0)
70 memset(&tx, 0, sizeof tx);
74 memmove(tx.score, score, VtScoreSize);
75 if(vtfcallrpc(z, &tx, &rx) < 0)
77 if(packetsize(rx.data) > n){
78 werrstr("read returned too much data");
82 if(ventidoublechecksha1){
83 packetsha1(rx.data, tx.score);
84 if(memcmp(score, tx.score, VtScoreSize) != 0){
85 werrstr("read asked for %V got %V", score, tx.score);
94 vtread(VtConn *z, uchar score[VtScoreSize], uint type, uchar *buf, int n)
99 if((p = vtreadpacket(z, score, type, n)) == nil)
102 if(packetconsume(p, buf, nn) < 0)
109 vtwritepacket(VtConn *z, uchar score[VtScoreSize], uint type, Packet *p)
113 if(packetsize(p) == 0){
114 memmove(score, vtzeroscore, VtScoreSize);
120 if(ventidoublechecksha1)
121 packetsha1(p, score);
122 if(vtfcallrpc(z, &tx, &rx) < 0)
124 if(ventidoublechecksha1){
125 if(memcmp(score, rx.score, VtScoreSize) != 0){
126 werrstr("sha1 hash mismatch: want %V got %V", score, rx.score);
130 memmove(score, rx.score, VtScoreSize);
135 vtwrite(VtConn *z, uchar score[VtScoreSize], uint type, uchar *buf, int n)
140 p = packetforeign(buf, n, 0, nil);
141 nn = vtwritepacket(z, score, type, p);
152 return vtfcallrpc(z, &tx, &rx);
161 return vtfcallrpc(z, &tx, &rx);