multi: add custom error messages to channel acceptor

This commit adds an optional error message to the channel acceptor's
reponse to allow operators to inform (or insult) unsuccessful channel
initiators as to the reason for their rejection.

This field is added in addition to the existing accept field to maintain
backwards compatibity. If we were to deprecate accept and interpret a
non-nil error as rejecting the channel, then received a response with
accept=false and a nil error, the server cannot tell whether this is a
legacy rejection or new mesage type acceptance (due to nil error),
so we keep both fields.
This commit is contained in:
carla committed 2020-11-10 11:38:47 +02:00
1 parent 54c3e98b40
commit 38fd7d206f
9 files changed
+1003 -715

No files matched your search

+18 -10
View File
@@ -46,18 +46,26 @@ func (c *ChainedAcceptor) RemoveAcceptor(id uint64) {
// and returns the conjunction of all these predicates.
//
// NOTE: Part of the ChannelAcceptor interface.
func (c *ChainedAcceptor) Accept(req *ChannelAcceptRequest) bool {
result := true
func (c *ChainedAcceptor) Accept(req *ChannelAcceptRequest) *ChannelAcceptResponse {
c.acceptorsMtx.RLock()
for _, acceptor := range c.acceptors {
// We call Accept first in case any acceptor (perhaps an RPCAcceptor)
// wishes to be notified about ChannelAcceptRequest.
result = acceptor.Accept(req) && result
}
c.acceptorsMtx.RUnlock()
defer c.acceptorsMtx.RUnlock()
return result
for _, acceptor := range c.acceptors {
// Call our acceptor to determine whether we want to accept this
// channel.
acceptorResponse := acceptor.Accept(req)
// If we should reject the channel, we can just exit early. This
// has the effect of returning the error belonging to our first
// failed acceptor.
if acceptorResponse.RejectChannel() {
return acceptorResponse
}
}
// If we have gone through all of our acceptors with no objections, we
// can return an acceptor with a nil error.
return NewChannelAcceptResponse(true, nil)
}
// A compile-time constraint to ensure ChainedAcceptor implements the