Skip to content

Commit

Permalink
peer: simplify MsgRouter with new fn tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ProofOfKeags committed Aug 14, 2024
1 parent 014fe89 commit ce594ed
Showing 1 changed file with 31 additions and 67 deletions.
98 changes: 31 additions & 67 deletions peer/msg_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,50 +64,28 @@ type MsgRouter interface {
Stop()
}

// queryMsg is a message sent into the main event loop to query or modify the
// internal state.
type queryMsg[Q any, R any] struct {
query Q

respChan chan fn.Either[R, error]
}

// sendQuery sends a query to the main event loop, and returns the response.
func sendQuery[Q any, R any](sendChan chan queryMsg[Q, R], queryArg Q,
quit chan struct{}) fn.Either[R, error] {
func sendQuery[Q any, R any](sendChan chan fn.Req[Q, R], queryArg Q,

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run macOS itest

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-notxindex, backend="bitcoind notxindex")

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind, backend=bitcoind cover=1)

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / RPC and mobile compilation check

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / check commits

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling" cover=1)

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (btcd, backend=btcd cover=1)

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run windows itest

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (neutrino, backend=neutrino cover=1)

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-cover)

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

undefined: fn.Req

Check failure on line 68 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-race)

undefined: fn.Req
quit chan struct{}) fn.Result[R] {

query := queryMsg[Q, R]{
query: queryArg,
respChan: make(chan fn.Either[R, error], 1),
}
query, respChan := fn.NewReq[Q, R](queryArg)

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run macOS itest

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-notxindex, backend="bitcoind notxindex")

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind, backend=bitcoind cover=1)

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / RPC and mobile compilation check

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / check commits

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling" cover=1)

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (btcd, backend=btcd cover=1)

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run windows itest

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (neutrino, backend=neutrino cover=1)

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-cover)

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

undefined: fn.NewReq

Check failure on line 71 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-race)

undefined: fn.NewReq

if !fn.SendOrQuit(sendChan, query, quit) {
return fn.NewRight[R](fmt.Errorf("router shutting down"))
}

resp, err := fn.RecvResp(query.respChan, nil, quit)
if err != nil {
return fn.NewRight[R](err)
return fn.Errf[R]("router shutting down")
}

return resp
return fn.NewResult(fn.RecvResp(respChan, nil, quit))

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run macOS itest

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-notxindex, backend="bitcoind notxindex")

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind, backend=bitcoind cover=1)

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / RPC and mobile compilation check

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / check commits

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling" cover=1)

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (btcd, backend=btcd cover=1)

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run windows itest

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (neutrino, backend=neutrino cover=1)

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-cover)

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

not enough arguments in call to fn.NewResult

Check failure on line 77 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-race)

not enough arguments in call to fn.NewResult
}

// sendQueryErr is a helper function based on sendQuery that can be used when
// the query only needs an error response.
func sendQueryErr[Q any](sendChan chan queryMsg[Q, error], queryArg Q,
func sendQueryErr[Q any](sendChan chan fn.Req[Q, error], queryArg Q,

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run macOS itest

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-notxindex, backend="bitcoind notxindex")

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind, backend=bitcoind cover=1)

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / RPC and mobile compilation check

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / check commits

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling" cover=1)

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (btcd, backend=btcd cover=1)

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run windows itest

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (neutrino, backend=neutrino cover=1)

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-cover)

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

undefined: fn.Req

Check failure on line 82 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-race)

undefined: fn.Req
quitChan chan struct{}) error {

var err error
resp := sendQuery(sendChan, queryArg, quitChan)
resp.WhenRight(func(e error) {
err = e
})
resp.WhenLeft(func(e error) {
err = e
})

return err
return fn.ElimEither(
fn.Iden, fn.Iden,
sendQuery(sendChan, queryArg, quitChan).Either,

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run macOS itest

cannot infer R (/Users/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-notxindex, backend="bitcoind notxindex")

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind, backend=bitcoind cover=1)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / RPC and mobile compilation check

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / check commits

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling" cover=1)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (btcd, backend=btcd cover=1)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run windows itest

cannot infer R (D:\a\lnd\lnd\peer\msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (neutrino, backend=neutrino cover=1)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-cover)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)

Check failure on line 87 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-race)

cannot infer R (/home/runner/work/lnd/lnd/peer/msg_router.go:68:23)
)
}

// EndpointsMap is a map of all registered endpoints.
Expand All @@ -121,19 +99,19 @@ type MultiMsgRouter struct {
stopOnce sync.Once

// registerChan is the channel that all new endpoints will be sent to.
registerChan chan queryMsg[MsgEndpoint, error]
registerChan chan fn.Req[MsgEndpoint, error]

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run macOS itest

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-notxindex, backend="bitcoind notxindex")

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind, backend=bitcoind cover=1)

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / RPC and mobile compilation check

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / check commits

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling" cover=1)

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (btcd, backend=btcd cover=1)

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run windows itest

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (neutrino, backend=neutrino cover=1)

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-cover)

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

undefined: fn.Req

Check failure on line 102 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-race)

undefined: fn.Req

// unregisterChan is the channel that all endpoints that are to be
// removed are sent to.
unregisterChan chan queryMsg[EndPointName, error]
unregisterChan chan fn.Req[EndPointName, error]

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run macOS itest

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-notxindex, backend="bitcoind notxindex")

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind, backend=bitcoind cover=1)

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / RPC and mobile compilation check

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / check commits

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling" cover=1)

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (btcd, backend=btcd cover=1)

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run windows itest

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (neutrino, backend=neutrino cover=1)

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-cover)

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

undefined: fn.Req

Check failure on line 106 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-race)

undefined: fn.Req

// msgChan is the channel that all messages will be sent to for
// processing.
msgChan chan queryMsg[lnwire.Message, error]
msgChan chan fn.Req[lnwire.Message, error]

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run macOS itest

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-notxindex, backend="bitcoind notxindex")

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind, backend=bitcoind cover=1)

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / RPC and mobile compilation check

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / check commits

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling" cover=1)

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (btcd, backend=btcd cover=1)

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run windows itest

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (neutrino, backend=neutrino cover=1)

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-cover)

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

undefined: fn.Req

Check failure on line 110 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-race)

undefined: fn.Req

// endpointsQueries is a channel that all queries to the endpoints map
// will be sent to.
endpointQueries chan queryMsg[MsgEndpoint, EndpointsMap]
endpointQueries chan fn.Req[MsgEndpoint, EndpointsMap]

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run macOS itest

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-notxindex, backend="bitcoind notxindex")

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind, backend=bitcoind cover=1)

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / RPC and mobile compilation check

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / check commits

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling" cover=1)

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (btcd, backend=btcd cover=1)

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run windows itest

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (neutrino, backend=neutrino cover=1)

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-cover)

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

undefined: fn.Req

Check failure on line 114 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-race)

undefined: fn.Req

wg sync.WaitGroup
quit chan struct{}
Expand All @@ -142,10 +120,10 @@ type MultiMsgRouter struct {
// NewMultiMsgRouter creates a new instance of a peer message router.
func NewMultiMsgRouter() *MultiMsgRouter {
return &MultiMsgRouter{
registerChan: make(chan queryMsg[MsgEndpoint, error]),
unregisterChan: make(chan queryMsg[EndPointName, error]),
msgChan: make(chan queryMsg[lnwire.Message, error]),
endpointQueries: make(chan queryMsg[MsgEndpoint, EndpointsMap]),
registerChan: make(chan fn.Req[MsgEndpoint, error]),

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run macOS itest

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-notxindex, backend="bitcoind notxindex")

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind, backend=bitcoind cover=1)

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / RPC and mobile compilation check

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / check commits

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling" cover=1)

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (btcd, backend=btcd cover=1)

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run windows itest

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run ubuntu itests (neutrino, backend=neutrino cover=1)

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-cover)

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

undefined: fn.Req

Check failure on line 123 in peer/msg_router.go

View workflow job for this annotation

GitHub Actions / run unit tests (btcd unit-race)

undefined: fn.Req
unregisterChan: make(chan fn.Req[EndPointName, error]),
msgChan: make(chan fn.Req[lnwire.Message, error]),
endpointQueries: make(chan fn.Req[MsgEndpoint, EndpointsMap]),
quit: make(chan struct{}),
}
}
Expand Down Expand Up @@ -189,14 +167,10 @@ func (p *MultiMsgRouter) RouteMsg(msg lnwire.Message) error {

// Endpoints returns a list of all registered endpoints.
func (p *MultiMsgRouter) Endpoints() EndpointsMap {
resp := sendQuery(p.endpointQueries, nil, p.quit)

var endpoints EndpointsMap
resp.WhenLeft(func(e EndpointsMap) {
endpoints = e
})

return endpoints
return fn.ElimEither(
fn.Iden, fn.Const[EndpointsMap, error](nil),
sendQuery(p.endpointQueries, nil, p.quit).Either,
)
}

// msgRouter is the main goroutine that handles all incoming messages.
Expand All @@ -211,7 +185,7 @@ func (p *MultiMsgRouter) msgRouter() {
// A new endpoint was just sent in, so we'll add it to our set
// of registered endpoints.
case newEndpointMsg := <-p.registerChan:
endpoint := newEndpointMsg.query
endpoint := newEndpointMsg.Request

peerLog.Infof("MsgRouter: registering new "+
"MsgEndpoint(%s)", endpoint.Name())
Expand All @@ -223,36 +197,29 @@ func (p *MultiMsgRouter) msgRouter() {
"duplicate endpoint: %v",
endpoint.Name())

newEndpointMsg.respChan <- fn.NewRight[error](
ErrDuplicateEndpoint,
)
newEndpointMsg.Resolve(ErrDuplicateEndpoint)

continue
}

endpoints[endpoint.Name()] = endpoint

// TODO(roasbeef): put in method?
newEndpointMsg.respChan <- fn.NewRight[error, error](
nil,
)
newEndpointMsg.Resolve(nil)

// A request to unregister an endpoint was just sent in, so
// we'll attempt to remove it.
case endpointName := <-p.unregisterChan:
delete(endpoints, endpointName.query)
delete(endpoints, endpointName.Request)

peerLog.Infof("MsgRouter: unregistering "+
"MsgEndpoint(%s)", endpointName.query)
"MsgEndpoint(%s)", endpointName.Request)

endpointName.respChan <- fn.NewRight[error, error](
nil,
)
endpointName.Resolve(nil)

// A new message was just sent in. We'll attempt to route it to
// all the endpoints that can handle it.
case msgQuery := <-p.msgChan:
msg := msgQuery.query
msg := msgQuery.Request

// Loop through all the endpoints and send the message
// to those that can handle it the message.
Expand All @@ -276,18 +243,15 @@ func (p *MultiMsgRouter) msgRouter() {
err = ErrUnableToRouteMsg
}

msgQuery.respChan <- fn.NewRight[error](err)
msgQuery.Resolve(err)

// A query for the endpoint state just came in, we'll send back
// a copy of our current state.
case endpointQuery := <-p.endpointQueries:
endpointsCopy := make(EndpointsMap, len(endpoints))
maps.Copy(endpointsCopy, endpoints)

//nolint:lll
endpointQuery.respChan <- fn.NewLeft[EndpointsMap, error](
endpointsCopy,
)
endpointQuery.Resolve(endpointsCopy)

case <-p.quit:
return
Expand Down

0 comments on commit ce594ed

Please sign in to comment.