You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nnet/packet/processor_nnet.go

41 lines
1013 B
Go

package packet
import (
"fmt"
"git.noahlan.cn/northlan/nnet/log"
"git.noahlan.cn/northlan/nnet/nface"
)
type NNetProcessor struct{}
func NewNNetProcessor() Processor {
return &NNetProcessor{}
}
func (d *NNetProcessor) ProcessPacket(conn nface.IConnection, packet interface{}) error {
p := packet.(*Packet)
switch p.Type {
case Handshake:
// TODO validate handshake
if _, err := conn.Conn().Write([]byte{}); err != nil {
return err
}
conn.SetStatus(nface.StatusPrepare)
log.Debugf("Connection handshake Id=%d, Remote=%s", conn.ID(), conn.Conn().RemoteAddr())
case HandshakeAck:
conn.SetStatus(nface.StatusWorking)
log.Debugf("Receive handshake ACK Id=%d, Remote=%s", conn.ID(), conn.Conn().RemoteAddr())
case Data:
if conn.Status() < nface.StatusWorking {
return fmt.Errorf("receive data on socket which not yet ACK, session will be closed immediately, remote=%s",
conn.Conn().RemoteAddr())
}
// TODO message data 处理
case Heartbeat:
// expected
}
return nil
}