package session import ( "net" "ripple/handler" "ripple/lockstep" "ripple/transport" "ripple/types" ) type AccountSession struct { transport *transport.AccountTransport lockstep *lockstep.Lockstep cmdHandlers [128]func(types.UserIdentifier, []byte) } func NewAccountSession( transport *transport.AccountTransport, lockstep *lockstep.Lockstep, h *handler.AccountHandlers, ) *AccountSession { s := &AccountSession{transport: transport, lockstep: lockstep} s.cmdHandlers[0x00] = h.FindPath s.cmdHandlers[0x01] = h.PathRecurse s.cmdHandlers[0x02] = h.PathFound s.cmdHandlers[0x03] = h.PreparePath return s } func (s *AccountSession) Receive(tx []byte, addr *net.UDPAddr) (types.Transaction, error) { return s.transport.Receive(tx, addr) } func (s *AccountSession) Dispatch(tx types.Transaction) { if tx.Instruction.Command & 0x80 == 0 { s.lockstep.ProcessInbound(tx) } else { tx.Instruction.Command &= 0x7F if h := s.cmdHandlers[tx.Instruction.Command]; h != nil { h(tx.Identifier, tx.Instruction.Arguments) } } }