Skip to content

Commit

Permalink
tcpreuse: return an error on multiple listeners for the same addr+con…
Browse files Browse the repository at this point in the history
…ntype
  • Loading branch information
MarcoPolo committed Oct 31, 2024
1 parent c02b0f9 commit cadd881
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions p2p/transport/tcpreuse/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,21 @@ type multiplexedListener struct {
wg sync.WaitGroup
}

var ErrListenerExists = errors.New("listener already exists for this conn type on this address")

func (m *multiplexedListener) DemultiplexedListen(connType DemultiplexedConnType) (manet.Listener, error) {
if !connType.IsKnown() {
return nil, fmt.Errorf("unknown connection type: %s", connType)
}

m.mx.Lock()
defer m.mx.Unlock()
l, ok := m.listeners[connType]
if ok {
return l, nil
if _, ok := m.listeners[connType]; ok {
return nil, ErrListenerExists
}

ctx, cancel := context.WithCancel(m.ctx)
l = &demultiplexedListener{
l := &demultiplexedListener{
buffer: make(chan manet.Conn),
inner: m.Listener,
ctx: ctx,
Expand Down

0 comments on commit cadd881

Please sign in to comment.