6 vtfcallrpc(VtConn *z, VtFcall *ou, VtFcall *in)
13 if((p = vtrpc(z, p)) == nil)
15 if(vtfcallunpack(in, p) < 0){
19 if(in->type == VtRerror){
25 if(in->type != ou->type+1){
26 werrstr("type mismatch: sent %c%d got %c%d",
27 "TR"[ou->type&1], ou->type>>1,
28 "TR"[in->type&1], in->type>>1);
42 memset(&tx, 0, sizeof tx);
44 tx.version = z->version;
48 if(vtfcallrpc(z, &tx, &rx) < 0)
57 vtreadpacket(VtConn *z, uchar score[VtScoreSize], uint type, int n)
61 memset(&tx, 0, sizeof tx);
65 memmove(tx.score, score, VtScoreSize);
66 if(vtfcallrpc(z, &tx, &rx) < 0)
68 if(packetsize(rx.data) > n){
69 werrstr("read returned too much data");
73 packetsha1(rx.data, tx.score);
74 if(memcmp(score, tx.score, VtScoreSize) != 0){
75 werrstr("read asked for %V got %V", score, tx.score);
84 vtread(VtConn *z, uchar score[VtScoreSize], uint type, uchar *buf, int n)
89 if((p = vtreadpacket(z, score, type, n)) == nil)
92 if(packetconsume(p, buf, nn) < 0)
98 vtwritepacket(VtConn *z, uchar score[VtScoreSize], uint type, Packet *p)
105 packetsha1(p, score);
106 if(vtfcallrpc(z, &tx, &rx) < 0)
108 if(memcmp(score, rx.score, VtScoreSize) != 0){
109 werrstr("sha1 hash mismatch: want %V got %V", score, rx.score);
116 vtwrite(VtConn *z, uchar score[VtScoreSize], uint type, uchar *buf, int n)
120 p = packetforeign(buf, n, nil, nil);
121 return vtwritepacket(z, score, type, p);
130 return vtfcallrpc(z, &tx, &rx);
139 return vtfcallrpc(z, &tx, &rx);