2bd2e2e5ce
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.
28 lines
912 B
Go
28 lines
912 B
Go
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)
|