Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions multi_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,41 @@ type MultiListener struct {
}

func (self *MultiListener) AcceptUnderlay(underlay Underlay) {
self.lock.Lock()
defer self.lock.Unlock()

log := pfxlog.Logger().WithField("underlayId", underlay.ConnectionId()).
WithField("underlayType", GetUnderlayType(underlay))

chId := underlay.ConnectionId()

if mc, ok := self.channels[chId]; ok {
self.lock.Lock()
mc, ok := self.channels[chId]
self.lock.Unlock()

if ok {
log.Info("found existing channel for underlay")
mc.AcceptUnderlay(underlay)
} else {
log.Info("no existing channel found for underlay")
mc, err := self.channelFactory(underlay, func() {
var err error
mc, err = self.channelFactory(underlay, func() {
self.CloseChannel(chId)
})

if mc != nil {
if err != nil {
pfxlog.Logger().WithError(err).Errorf("failed to create multi-underlay channel")
} else {
self.lock.Lock()
self.channels[chId] = mc
self.lock.Unlock()
}
}
}
}

func (self *MultiListener) CloseChannel(chId string) {
self.lock.Lock()
defer self.lock.Unlock()
delete(self.channels, chId)
self.lock.Unlock()
}

func NewMultiListener(channelF MultiChannelFactory) *MultiListener {
Expand Down
Loading