Skip to content

Commit

Permalink
Merge pull request #525 from openziti/add-get-circuit-id
Browse files Browse the repository at this point in the history
Add GetCircuitId to edge.Conn. Fixes #524
  • Loading branch information
plorenz authored Mar 15, 2024
2 parents 17c09fe + 837d1ce commit d058dff
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Release 0.23.11

## What's New

* Add GetCircuitId to edge.Conn. Allows correlation with controller/router metrics. Requires support from controller.

# Release 0.23.4

## What's New
Expand Down
1 change: 1 addition & 0 deletions ziti/edge/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type ServiceConn interface {
GetAppData() []byte
SourceIdentifier() string
TraceRoute(hops uint32, timeout time.Duration) (*TraceRouteResult, error)
GetCircuitId() string
}

type Conn interface {
Expand Down
1 change: 1 addition & 0 deletions ziti/edge/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const (
SupportsInspectHeader = 1023
SupportsBindSuccessHeader = 1024
ConnectionMarkerHeader = 1025
CircuitIdHeader = 1026

ErrorCodeInternal = 1
ErrorCodeInvalidApiSession = 2
Expand Down
11 changes: 10 additions & 1 deletion ziti/edge/network/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type edgeConn struct {
acceptCompleteHandler *newConnHandler
connType ConnType
marker string
circuitId string

crypto bool
keyPair *kx.KeyPair
Expand Down Expand Up @@ -251,6 +252,10 @@ func (conn *edgeConn) HandleMuxClose() error {
return nil
}

func (conn *edgeConn) GetCircuitId() string {
return conn.circuitId
}

func (conn *edgeConn) HandleClose(channel.Channel) {
logger := pfxlog.Logger().WithField("connId", conn.Id()).WithField("marker", conn.marker)
defer logger.Debug("received HandleClose from underlying channel, marking conn closed")
Expand Down Expand Up @@ -306,6 +311,7 @@ func (conn *edgeConn) Connect(session *rest_model.SessionDetail, options *edge.D
logger.Warn("connection is not end-to-end-encrypted")
}
}
conn.circuitId, _ = replyMsg.GetStringHeader(edge.CircuitIdHeader)
logger.Debug("connected")

return conn, nil
Expand Down Expand Up @@ -583,6 +589,7 @@ func (conn *edgeConn) newChildConnection(message *channel.Message) {

sourceIdentity, _ := message.GetStringHeader(edge.CallerIdHeader)
marker, _ := message.GetStringHeader(edge.ConnectionMarkerHeader)
circuitId, _ := message.GetStringHeader(edge.CircuitIdHeader)

edgeCh := &edgeConn{
MsgChannel: *edge.NewEdgeMsgChannel(conn.Channel, id),
Expand All @@ -593,13 +600,15 @@ func (conn *edgeConn) newChildConnection(message *channel.Message) {
appData: message.Headers[edge.AppDataHeader],
connType: ConnTypeDial,
marker: marker,
circuitId: circuitId,
}

newConnLogger := pfxlog.Logger().
WithField("marker", marker).
WithField("connId", id).
WithField("parentConnId", conn.Id()).
WithField("token", token)
WithField("token", token).
WithField("circuitId", token)

err := conn.msgMux.AddMsgSink(edgeCh) // duplicate errors only happen on the server side, since client controls ids
if err != nil {
Expand Down

0 comments on commit d058dff

Please sign in to comment.