Ejemplo n.º 1
0
func HandleConnection(conn *tufer.Connection, ctx *Context) {
	defer conn.Close()
	ctx.LogDebug("Handle Connection")
	err := Handshake(conn, ctx)

	if err != nil {
		ctx.LogWarn("Handshake failed:", err)
	}

}
Ejemplo n.º 2
0
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

}
Ejemplo n.º 3
0
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
}