Add names to nameless routes (#1986)

* add names to nameless routes

* Update router.go

Co-authored-by: Ori Newman <orinewman1@gmail.com>
This commit is contained in:
Aleoami 2022-03-28 09:41:25 +03:00 committed by GitHub
parent 58d627e05a
commit 2eca0f0b5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -128,7 +128,7 @@ func (na *NetAdapter) P2PConnectionCount() int {
}
func (na *NetAdapter) onP2PConnectedHandler(connection server.Connection) error {
netConnection := newNetConnection(connection, na.p2pRouterInitializer)
netConnection := newNetConnection(connection, na.p2pRouterInitializer, "on P2P connected")
na.p2pConnectionsLock.Lock()
defer na.p2pConnectionsLock.Unlock()
@ -148,7 +148,7 @@ func (na *NetAdapter) onP2PConnectedHandler(connection server.Connection) error
}
func (na *NetAdapter) onRPCConnectedHandler(connection server.Connection) error {
netConnection := newNetConnection(connection, na.rpcRouterInitializer)
netConnection := newNetConnection(connection, na.rpcRouterInitializer, "on RPC connected")
netConnection.setOnDisconnectedHandler(func() {})
netConnection.start()

View File

@ -20,8 +20,8 @@ type NetConnection struct {
isRouterClosed uint32
}
func newNetConnection(connection server.Connection, routerInitializer RouterInitializer) *NetConnection {
router := routerpkg.NewRouter()
func newNetConnection(connection server.Connection, routerInitializer RouterInitializer, name string) *NetConnection {
router := routerpkg.NewRouter(name)
netConnection := &NetConnection{
connection: connection,

View File

@ -24,10 +24,10 @@ type Router struct {
}
// NewRouter creates a new empty router
func NewRouter() *Router {
func NewRouter(name string) *Router {
router := Router{
incomingRoutes: make(map[appmessage.MessageCommand]*Route),
outgoingRoute: newRouteWithCapacity("", outgoingRouteMaxMessages),
outgoingRoute: newRouteWithCapacity(fmt.Sprintf("%s - outgoing", name), outgoingRouteMaxMessages),
}
return &router
}

View File

@ -11,7 +11,7 @@ type rpcRouter struct {
}
func buildRPCRouter() (*rpcRouter, error) {
router := routerpkg.NewRouter()
router := routerpkg.NewRouter("RPC server")
routes := make(map[appmessage.MessageCommand]*routerpkg.Route, len(appmessage.RPCMessageCommandToString))
for messageType := range appmessage.RPCMessageCommandToString {
route, err := router.AddIncomingRoute("rpc client", []appmessage.MessageCommand{messageType})