Skip to content

Commit e0a9df8

Browse files
committed
Allow injecting the underlay type into messages. Fixes #222
1 parent f3ca15a commit e0a9df8

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

impl.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ import (
2020
"container/heap"
2121
"crypto/x509"
2222
"fmt"
23-
"github.com/michaelquigley/pfxlog"
24-
"github.com/openziti/foundation/v2/concurrenz"
25-
"github.com/openziti/foundation/v2/info"
26-
"github.com/openziti/foundation/v2/sequence"
27-
"github.com/pkg/errors"
2823
"io"
2924
"net"
3025
"sync"
3126
"sync/atomic"
3227
"time"
28+
29+
"github.com/michaelquigley/pfxlog"
30+
"github.com/openziti/foundation/v2/concurrenz"
31+
"github.com/openziti/foundation/v2/info"
32+
"github.com/openziti/foundation/v2/sequence"
33+
"github.com/pkg/errors"
3334
)
3435

3536
const (
36-
flagClosed = 0
37-
flagRxStarted = 1
37+
flagClosed = 0
38+
flagRxStarted = 1
39+
flagInjectUnderlayType = 2
3840
)
3941

4042
var connectionSeq = sequence.NewSequence()

message.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import (
2121
"context"
2222
"encoding/binary"
2323
"fmt"
24-
"github.com/michaelquigley/pfxlog"
25-
"github.com/pkg/errors"
2624
"io"
2725
"time"
26+
27+
"github.com/michaelquigley/pfxlog"
28+
"github.com/pkg/errors"
2829
)
2930

3031
/**
@@ -50,6 +51,7 @@ const (
5051
IsGroupedHeader = 9
5152
GroupSecretHeader = 10
5253
IsFirstGroupConnection = 11
54+
UnderlayTypeHeader = 12
5355

5456
// Headers in the range 128-255 inclusive will be reflected when creating replies
5557
ReflectedHeaderBitMask = 1 << 7

multi.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type MultiChannelConfig struct {
4040
UnderlayHandler UnderlayHandler
4141
BindHandler BindHandler
4242
Underlay Underlay
43+
44+
InjectUnderlayTypeIntoMessages bool
4345
}
4446

4547
type senderContextImpl struct {
@@ -110,6 +112,8 @@ func NewMultiChannel(config *MultiChannelConfig) (MultiChannel, error) {
110112
underlayHandler: config.UnderlayHandler,
111113
}
112114

115+
impl.flags.Set(flagInjectUnderlayType, config.InjectUnderlayTypeIntoMessages)
116+
113117
impl.ownerId = config.Underlay.Id()
114118
impl.certs.Store(config.Underlay.Certificates())
115119
impl.headers.Store(config.Underlay.Headers())
@@ -495,6 +499,9 @@ func (self *multiChannelImpl) Rxer(underlay Underlay, notifier *CloseNotifier) {
495499
log.Debug("started")
496500
defer log.Debug("exited")
497501

502+
underlayType := GetUnderlayType(underlay)
503+
injectType := self.flags.IsSet(flagInjectUnderlayType)
504+
498505
for {
499506
m, err := underlay.Rx()
500507
if err != nil {
@@ -508,6 +515,9 @@ func (self *multiChannelImpl) Rxer(underlay Underlay, notifier *CloseNotifier) {
508515
return
509516
}
510517

518+
if injectType {
519+
m.Headers.PutStringHeader(UnderlayTypeHeader, underlayType)
520+
}
511521
self.Rx(m)
512522
}
513523
}

0 commit comments

Comments
 (0)