blob: ca34221e6864df5e1491e55129898280c320d554 [file] [log] [blame]
rsc056fe1b2003-11-23 18:19:58 +00001#include <u.h>
2#include <libc.h>
3#include <venti.h>
4
5int
6vtsrvhello(VtConn *z)
7{
8 VtFcall tx, rx;
9 Packet *p;
10
rsc361e2792005-01-18 20:15:18 +000011 if((p = vtrecv(z)) == nil)
rsc2e965b32004-05-05 04:22:16 +000012 return -1;
rsc056fe1b2003-11-23 18:19:58 +000013
14 if(vtfcallunpack(&tx, p) < 0){
15 packetfree(p);
rsc2e965b32004-05-05 04:22:16 +000016 return -1;
rsc056fe1b2003-11-23 18:19:58 +000017 }
18 packetfree(p);
19
rsc7643b262005-07-13 10:52:39 +000020 if(tx.msgtype != VtThello){
rsc056fe1b2003-11-23 18:19:58 +000021 vtfcallclear(&tx);
rsc7643b262005-07-13 10:52:39 +000022 werrstr("bad packet type %d; want Thello %d", tx.msgtype, VtThello);
rsc2e965b32004-05-05 04:22:16 +000023 return -1;
rsc056fe1b2003-11-23 18:19:58 +000024 }
25 if(tx.tag != 0){
26 vtfcallclear(&tx);
27 werrstr("bad tag in hello");
rsc2e965b32004-05-05 04:22:16 +000028 return -1;
rsc056fe1b2003-11-23 18:19:58 +000029 }
30 if(strcmp(tx.version, z->version) != 0){
31 vtfcallclear(&tx);
32 werrstr("bad version in hello");
rsc2e965b32004-05-05 04:22:16 +000033 return -1;
rsc056fe1b2003-11-23 18:19:58 +000034 }
35 vtfree(z->uid);
36 z->uid = tx.uid;
37 tx.uid = nil;
38 vtfcallclear(&tx);
39
40 memset(&rx, 0, sizeof rx);
rsc7643b262005-07-13 10:52:39 +000041 rx.msgtype = VtRhello;
rsc056fe1b2003-11-23 18:19:58 +000042 rx.tag = tx.tag;
43 rx.sid = "anonymous";
44 if((p = vtfcallpack(&rx)) == nil)
rsc2e965b32004-05-05 04:22:16 +000045 return -1;
rsc056fe1b2003-11-23 18:19:58 +000046 if(vtsend(z, p) < 0)
rsc2e965b32004-05-05 04:22:16 +000047 return -1;
rsc056fe1b2003-11-23 18:19:58 +000048
rsc2e965b32004-05-05 04:22:16 +000049 return 0;
rsc056fe1b2003-11-23 18:19:58 +000050}