func Handshake(conn *tufer.Connection, ctx *Context) (err error) { conn.SetDeadline(5) defer conn.ClearDeadline() // send id to client err = conn.WriteControlMessages(INITIAL_SERVER_ID, SERVER_CONTROL_PROTOCOL_VERSION) if err != nil { return } ctx.LogDebug("Wrote Control Messages") // client should send proper response msgs, err := conn.ReadControlMessages() if err != nil { return } ctx.LogDebug("Handshake:", msgs) validator := NewValidator() err = validator.ValidateInt(2, len(msgs)) if err != nil { return } validator.ValidateString(INITIAL_CLIENT_ID, msgs[0]) if err != nil { return } return }
func (c *Client) Handshake(conn *tufer.Connection) (err error) { msgs, err := conn.ReadControlMessages() if err != nil { return } v := NewFatalValidator(c.ctx) v.ValidateInt(len(msgs), 2) v.ValidateString(msgs[0], INITIAL_SERVER_ID) c.ctx.LogInfo("Handshake:", msgs) err = conn.WriteControlMessages(INITIAL_CLIENT_ID, CLIENT_CONTROL_PROTOCOL_VERSION) return }