package server import ( "ripple/handler" "ripple/lockstep" "ripple/datavisor" "ripple/services" "ripple/session" "ripple/state" "ripple/transport" "ripple/udpr" ) type Server struct { sockCh chan UdpDatagram sessionRouter *sessionRouter lockstep *lockstep.Lockstep paymentMgr *services.PaymentManager } func NewServer(sockCh chan UdpDatagram, conn *udpr.UDPRConn, d *transport.Data, st *state.State) *Server { accountTransport, accSendMgr := transport.NewAccountTransport(conn, d) userTransport := transport.NewUserTransport(conn, d) counterpartTransport := transport.NewCounterpartTransport(conn, d) lockstep := lockstep.NewLockstep(st, accountTransport) accountMgr := datavisor.NewAccountManager(st, d, lockstep, accSendMgr) paymentMgr := services.NewPaymentManager(st, d, lockstep, accountTransport) resilience := services.NewResilience(st, lockstep) lockstepHandlers := handler.NewLockstepHandlers(lockstep, counterpartTransport, resilience) accHandlers := handler.NewAccountHandlers(st, paymentMgr, accountTransport, counterpartTransport) userHandlers := handler.NewUserHandlers(st, accountMgr, paymentMgr, lockstep) counterpartHandlers := handler.NewCounterpartHandlers(st, lockstep, paymentMgr) lockstep.InitCmdHandlers(session.GetLockstepCmdHandlers(lockstepHandlers)) accountSession := session.NewAccountSession(accountTransport, lockstep, accHandlers) userSession := session.NewUserSession(userTransport, userHandlers) counterpartSession := session.NewCounterpartSession(st, counterpartTransport, counterpartHandlers) return &Server{ sockCh: sockCh, sessionRouter: newSessionRouter(accountSession, userSession, counterpartSession), lockstep: lockstep, paymentMgr: paymentMgr, } } func (s *Server) Run() { for { select { case dg, ok := <-s.sockCh: if !ok { return } s.sessionRouter.routeDatagram(dg) case <-s.lockstep.FailsafeCh: s.lockstep.SyncFailsafe() case <-s.paymentMgr.CancelFailsafeCh: s.paymentMgr.CancelPaymentFailsafe() case <-s.paymentMgr.ScheduleFeeCh: s.paymentMgr.CollectFees() case <-s.paymentMgr.FeeFailsafeCh: s.paymentMgr.PaymentFeeFailsafe() } } }