wgengine/magicsock: clean up discovery logging

Updates #483
This commit is contained in:
Brad Fitzpatrick
2020-07-02 10:48:13 -07:00
parent 056fbee4ef
commit 0f0ed3dca0
3 changed files with 32 additions and 12 deletions

View File

@@ -152,3 +152,17 @@ func parsePong(ver uint8, p []byte) (m *Pong, err error) {
m.Src.Port = binary.BigEndian.Uint16(p)
return m, nil
}
// MessageSummary returns a short summary of m for logging purposes.
func MessageSummary(m Message) string {
switch m := m.(type) {
case *Ping:
return fmt.Sprintf("ping tx=%x", m.TxID)
case *Pong:
return fmt.Sprintf("pong tx=%x", m.TxID)
case CallMeMaybe:
return fmt.Sprintf("call-me-maybe")
default:
return fmt.Sprintf("%#v", m)
}
}