Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed Mar 12, 2025
1 parent 7a87adc commit fbf732c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/openziti/foundation/v2 v2.0.58
github.com/openziti/identity v1.0.100
github.com/openziti/transport/v2 v2.0.165
github.com/orcaman/concurrent-map/v2 v2.0.1
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.9.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ github.com/openziti/identity v1.0.100 h1:FTkbhykDCMw1z/wxEeDfmq1aBp2tLRjZ3ggioRT
github.com/openziti/identity v1.0.100/go.mod h1:E4SHqfXaZldDCo/GIdSD/Xg61obuolWYg9Qe8lqGUrQ=
github.com/openziti/transport/v2 v2.0.165 h1:/ks1HSN/+cN7gX1ajyK8TnqEKPvtOmAhOoM34FzA7h4=
github.com/openziti/transport/v2 v2.0.165/go.mod h1:wgXqfcEeDKr+FIHhp4O4Q+FHT/2Q2WJK6ZsVWD8CY98=
github.com/orcaman/concurrent-map/v2 v2.0.1 h1:jOJ5Pg2w1oeB6PeDurIYf6k9PQ+aTITr/6lP/L/zp6c=
github.com/orcaman/concurrent-map/v2 v2.0.1/go.mod h1:9Eq3TG2oBe5FirmYWQfYO5iH1q0Jv47PLaNK++uCdOM=
github.com/parallaxsecond/parsec-client-go v0.0.0-20221025095442-f0a77d263cf9 h1:mOvehYivJ4Aqu2CPe3D3lv8jhqOI9/1o0THxJHBE0qw=
github.com/parallaxsecond/parsec-client-go v0.0.0-20221025095442-f0a77d263cf9/go.mod h1:gLH27qo/dvMhLTVVyMELpe3Tut7sOfkiDg7ZpeqKwsw=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
Expand Down
38 changes: 38 additions & 0 deletions multi_listener.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package channel

import (
"github.com/michaelquigley/pfxlog"
"sync"
)

type MultiChannelFactory func(underlay Underlay) (MultiChannel, error)

type MultiListener struct {
channels map[string]MultiChannel
lock sync.Mutex
channelFactory func(underlay Underlay) (MultiChannel, error)
}

func (self *MultiListener) AcceptUnderlay(underlay Underlay) {
self.lock.Lock()
defer self.lock.Unlock()
if mc, ok := self.channels[underlay.ConnectionId()]; ok {
mc.AcceptUnderlay(underlay)
} else {
mc, err := self.channelFactory(underlay)
if err != nil {
pfxlog.Logger().WithError(err).Errorf("failed to create multi-underlay channel")
} else {
self.channels[underlay.ConnectionId()] = mc
mc.AcceptUnderlay(underlay)
}
}
}

func NewMultiListener(channelF MultiChannelFactory) *MultiListener {
result := &MultiListener{
channels: make(map[string]MultiChannel),
channelFactory: channelF,
}
return result
}
28 changes: 28 additions & 0 deletions multi_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
package channel

import (
"github.com/michaelquigley/pfxlog"
"github.com/openziti/identity"
"github.com/openziti/transport/v2"
"github.com/stretchr/testify/require"
"io"
"sync"
"testing"
"time"
)

func Test_MultiUnderlayChannels(t *testing.T) {
req := require.New(t)
listenAddr, err := transport.ParseAddress("tcp:0.0.0.0:6767")
req.NoError(err)

multiListener := NewMultiListener(func(underlay Underlay) (MultiChannel, error) {
multiConfig := MultiChannelConfig{
LogicalName: "test",
DefaultSender: nil,
Options: nil,
UnderlayHandler: nil,
BindHandler: nil,
Underlay: underlay,
}
return NewMultiChannel(&multiConfig)
})

listener, err := NewClassicListenerF(&identity.TokenId{Token: "host"}, listenAddr, ListenerConfig{}, multiListener.AcceptUnderlay)
req.NoError(err)
defer func() { _ = listener.Close() }()
}

type EdgeChannel struct {
id string
ctrlSender Sender
Expand Down

0 comments on commit fbf732c

Please sign in to comment.