chanacceptor: Adding Chained and RPC acceptors

This commit introduces the chanacceptor package which is used
to determine, by a set of heuristics, which open channel messages
to accept and reject. Currently, two acceptors are implemented
via the ChannelAcceptor interface: ChainedAcceptor and RPCAcceptor.
The RPCAcceptor allows the RPC client to respond to the open channel
request, and the ChainedAcceptor allows a conjunction of acceptors
to be used.
This commit is contained in:
nsa
2019-08-07 22:15:14 -04:00
parent 7c6cee7c4f
commit 2bd2e2e5ce
3 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package chanacceptor
// RPCAcceptor represents the RPC-controlled variant of the ChannelAcceptor.
// One RPCAcceptor allows one RPC client.
type RPCAcceptor struct {
acceptClosure func(req *ChannelAcceptRequest) bool
}
// Accept is a predicate on the ChannelAcceptRequest which is sent to the RPC
// client who will respond with the ultimate decision. This assumes an accept
// closure has been specified during creation.
//
// NOTE: Part of the ChannelAcceptor interface.
func (r *RPCAcceptor) Accept(req *ChannelAcceptRequest) bool {
return r.acceptClosure(req)
}
// NewRPCAcceptor creates and returns an instance of the RPCAcceptor.
func NewRPCAcceptor(closure func(*ChannelAcceptRequest) bool) *RPCAcceptor {
return &RPCAcceptor{
acceptClosure: closure,
}
}
// A compile-time constraint to ensure RPCAcceptor implements the ChannelAcceptor
// interface.
var _ ChannelAcceptor = (*RPCAcceptor)(nil)