Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send bind success notifications to the SDK if supported #1579

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
github.com/openziti/jwks v1.0.3
github.com/openziti/metrics v1.2.40
github.com/openziti/runzmd v1.0.36
github.com/openziti/sdk-golang v0.20.139
github.com/openziti/sdk-golang v0.15.8-0.20231212210042-6e1737719bda
github.com/openziti/secretstream v0.1.14
github.com/openziti/storage v0.2.26
github.com/openziti/transport/v2 v2.0.119
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ github.com/openziti/metrics v1.2.40 h1:gySRgR8prCPqaEjmUtX0eXFs7NkI9uPAzp+z6A8+J
github.com/openziti/metrics v1.2.40/go.mod h1:HXdVryf3xpZfnY4VcaOjMxiBv+qw0wJlEJNLbooB9hY=
github.com/openziti/runzmd v1.0.36 h1:HOqTZFzTTFu52qmCAQfFvKDmCSl8ZqP1PQQ0UnJIA4E=
github.com/openziti/runzmd v1.0.36/go.mod h1:jYqummjskmFh63htJFF2SrUuvxNQifqd5REUhYVaY/A=
github.com/openziti/sdk-golang v0.20.139 h1:1TaRTd5KmSrfHR6W3ASuj651o37h4NOXTRC6K53Pf3k=
github.com/openziti/sdk-golang v0.20.139/go.mod h1:z2gUWwonLa+haq40cfsNE2P23RoD+SZhxWulG7w7aI0=
github.com/openziti/sdk-golang v0.15.8-0.20231212210042-6e1737719bda h1:zt8nJuqlH0XhQHOxQgjreUtILRvqW/KwscFS5ExYV+0=
github.com/openziti/sdk-golang v0.15.8-0.20231212210042-6e1737719bda/go.mod h1:16j+e3WI+ztxG1V+X8Wl3MFyAUe0BO8a8ypxbzDF7Ao=
github.com/openziti/secretstream v0.1.14 h1:Ta+nB5Prcct+L5LIKUA1nE56QhWS6lMPQYTlpxUltU0=
github.com/openziti/secretstream v0.1.14/go.mod h1:/hhuLfu+GIv0+cnapfsu/VOnXEvmTt3GKtCu+lQ0RIw=
github.com/openziti/storage v0.2.26 h1:15EbOC6A//dsdLSs/RYJP6Qn3Rj6Od4btXEWGezatxc=
Expand Down
29 changes: 15 additions & 14 deletions router/xgress_edge/fabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,21 @@ func (self terminatorState) String() string {

type edgeTerminator struct {
edge.MsgChannel
edgeClientConn *edgeClientConn
terminatorId concurrenz.AtomicValue[string]
listenerId string
token string
instance string
instanceSecret []byte
cost uint16
precedence edge_ctrl_pb.TerminatorPrecedence
hostData map[uint32][]byte
assignIds bool
onClose func()
v2 bool
state concurrenz.AtomicValue[terminatorState]
postValidate bool
edgeClientConn *edgeClientConn
terminatorId concurrenz.AtomicValue[string]
listenerId string
token string
instance string
instanceSecret []byte
cost uint16
precedence edge_ctrl_pb.TerminatorPrecedence
hostData map[uint32][]byte
assignIds bool
onClose func()
v2 bool
state concurrenz.AtomicValue[terminatorState]
postValidate bool
notifyEstablished bool
}

func (self *edgeTerminator) inspect(fixInvalidTerminators bool) (*edge.InspectResult, error) {
Expand Down
4 changes: 3 additions & 1 deletion router/xgress_edge/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/openziti/channel/v2"
"github.com/openziti/foundation/v2/versions"
"github.com/openziti/metrics"
"github.com/openziti/sdk-golang/ziti/edge"
"github.com/openziti/transport/v2"
"github.com/openziti/ziti/common/pb/edge_ctrl_pb"
"github.com/openziti/ziti/router"
Expand Down Expand Up @@ -156,7 +157,8 @@ func (factory *Factory) CreateListener(optionsData xgress.OptionsData) (xgress.L
}

headers := map[int32][]byte{
channel.HelloVersionHeader: versionHeader,
channel.HelloVersionHeader: versionHeader,
edge.SupportsBindSuccessHeader: {1},
}

return newListener(factory.env.GetRouterId(), factory, options, headers), nil
Expand Down
11 changes: 11 additions & 0 deletions router/xgress_edge/hosted.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ func (self *hostedServiceRegistry) HandleCreateTerminatorResponse(msg *channel.M
} else {
log.Info("received additional terminator created notification")
}

if terminator.notifyEstablished {
go func() {
notifyMsg := channel.NewMessage(edge.ContentTypeBindSuccess, nil)
notifyMsg.PutUint32Header(edge.ConnIdHeader, terminator.MsgChannel.Id())

if err := notifyMsg.WithTimeout(time.Second * 30).Send(terminator.MsgChannel.Channel); err != nil {
log.WithError(err).Error("failed to send bind success")
}
}()
}
}

func (self *hostedServiceRegistry) waitForTerminatorCreated(id string, timeout time.Duration) bool {
Expand Down
29 changes: 14 additions & 15 deletions router/xgress_edge/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,23 +387,22 @@ func (self *edgeClientConn) processBindV2(req *channel.Message, ch channel.Chann
hostData[edge.PublicKeyHeader] = pubKey
}

postValidate := false
if supportsInspect, _ := req.GetBoolHeader(edge.SupportsInspectHeader); supportsInspect {
postValidate = true
}
postValidate, _ := req.GetBoolHeader(edge.SupportsInspectHeader)
notifyEstablished, _ := req.GetBoolHeader(edge.SupportsBindSuccessHeader)

terminator := &edgeTerminator{
MsgChannel: *edge.NewEdgeMsgChannel(self.ch, connId),
edgeClientConn: self,
token: token,
cost: cost,
precedence: precedence,
instance: terminatorInstance,
instanceSecret: terminatorInstanceSecret,
hostData: hostData,
assignIds: assignIds,
v2: true,
postValidate: postValidate,
MsgChannel: *edge.NewEdgeMsgChannel(self.ch, connId),
edgeClientConn: self,
token: token,
cost: cost,
precedence: precedence,
instance: terminatorInstance,
instanceSecret: terminatorInstanceSecret,
hostData: hostData,
assignIds: assignIds,
v2: true,
postValidate: postValidate,
notifyEstablished: notifyEstablished,
}
terminator.terminatorId.Store(terminatorId)

Expand Down
7 changes: 2 additions & 5 deletions tests/addressable_terminators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ func Test_AddressableTerminators(t *testing.T) {

ctx.CreateEnrollAndStartEdgeRouter()

watcher := ctx.AdminManagementSession.newTerminatorWatcher()
defer watcher.Close()

type host struct {
id *identity
context ziti.Context
Expand All @@ -59,10 +56,10 @@ func Test_AddressableTerminators(t *testing.T) {
defer host.context.Close()

host.listener, err = host.context.ListenWithOptions(service.Name, &ziti.ListenOptions{
BindUsingEdgeIdentity: true,
BindUsingEdgeIdentity: true,
WaitForNEstablishedListeners: 1,
})
ctx.Req.NoError(err)
watcher.waitForTerminators(service.Id, 1, 5*time.Second)
}

type client struct {
Expand Down
Loading