-
Notifications
You must be signed in to change notification settings - Fork 82
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
Modify Status command to return a ConnTypeLabel in addition to the ConnType byte #471
base: devel
Are you sure you want to change the base?
Changes from all commits
054eb5d
15690c1
a8ffb72
d603d20
855c3fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,14 +218,24 @@ type routingUpdate struct { | |
} | ||
|
||
const ( | ||
// If adding/changing an ConnType, make sure to change ConnTypeStrings as well. | ||
// These are friendly strings printed out in a status command. | ||
// ConnTypeDatagram indicates a packetconn (datagram) service listener. | ||
ConnTypeDatagram = 0 | ||
// ConnTypeStream indicates a conn (stream) service listener, without a user-defined TLS. | ||
ConnTypeStream = 1 | ||
// ConnTypeStreamTLS indicates the service listens on a packetconn connection, with a user-defined TLS. | ||
ConnTypeStreamTLS = 2 | ||
// Default Label for an unknown connection type. | ||
UnknownConnTypeStr = "Unknown" | ||
) | ||
|
||
var ConnTypeStrings = map[byte]string{ | ||
ConnTypeDatagram: "Datagram", | ||
ConnTypeStream: "Stream", | ||
ConnTypeStreamTLS: "StreamTLS", | ||
} | ||
|
||
// WorkCommand tracks available work types and whether they verify work submissions. | ||
type WorkCommand struct { | ||
WorkType string | ||
|
@@ -235,12 +245,13 @@ type WorkCommand struct { | |
|
||
// ServiceAdvertisement is the data associated with a service advertisement. | ||
type ServiceAdvertisement struct { | ||
NodeID string | ||
Service string | ||
Time time.Time | ||
ConnType byte | ||
Tags map[string]string | ||
WorkCommands []WorkCommand | ||
NodeID string | ||
Service string | ||
Time time.Time | ||
ConnType byte | ||
ConnTypeLabel string | ||
Tags map[string]string | ||
WorkCommands []WorkCommand | ||
} | ||
|
||
// serviceAdvertisementFull is the whole message from the network. | ||
|
@@ -437,6 +448,17 @@ func (s *Netceptor) MaxConnectionIdleTime() time.Duration { | |
return s.maxConnectionIdleTime | ||
} | ||
|
||
// Convert the connection type to a string. | ||
func (s *Netceptor) GetConnectionTypeAsString(connectionType byte) string { | ||
// A byte can't be < 0 so we don't need to check the lower bounds | ||
connTypeString, ok := ConnTypeStrings[connectionType] | ||
if !ok { | ||
connTypeString = UnknownConnTypeStr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious, under which conditions would this happen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone added a new connection type constant but forgot to add an entry into the map. I was also thinking of some weird upgrade scenario where a newer version of receptor with a new connection type was introduced to an existing mesh. |
||
} | ||
|
||
return connTypeString | ||
} | ||
|
||
type backendInfo struct { | ||
connectionCost float64 | ||
nodeCost map[string]float64 | ||
|
@@ -579,6 +601,7 @@ func (s *Netceptor) Status() Status { | |
adCopy.WorkCommands = s.workCommands | ||
} | ||
} | ||
adCopy.ConnTypeLabel = s.GetConnectionTypeAsString(adCopy.ConnType) | ||
serviceAds = append(serviceAds, &adCopy) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably shouldn't go here. This is the struct for the low-level advertisements that get sent around the network, so its size matters. If we want another field in the Status response, we should define another struct that inherits this one and adds the field, and populate it at the time the status is being asked for.