From: Matt Joiner Date: Wed, 8 Nov 2017 08:29:55 +0000 (+1100) Subject: The "m" field in the extended handshake is not mandatory X-Git-Tag: v1.0.0~336 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=1b9606ae75c2448155bf769e4f334813867ea2a6;p=btrtrc.git The "m" field in the extended handshake is not mandatory --- diff --git a/connection.go b/connection.go index 6b83868e..c52328a0 100644 --- a/connection.go +++ b/connection.go @@ -892,32 +892,29 @@ func (c *connection) mainReadLoop() error { if v, ok := d["v"]; ok { c.PeerClientName = v.(string) } - m, ok := d["m"] - if !ok { - err = errors.New("handshake missing m item") - break - } - mTyped, ok := m.(map[string]interface{}) - if !ok { - err = errors.New("handshake m value is not dict") - break - } - if c.PeerExtensionIDs == nil { - c.PeerExtensionIDs = make(map[string]byte, len(mTyped)) - } - for name, v := range mTyped { - id, ok := v.(int64) + if m, ok := d["m"]; ok { + mTyped, ok := m.(map[string]interface{}) if !ok { - log.Printf("bad handshake m item extension ID type: %T", v) - continue + err = errors.New("handshake m value is not dict") + break } - if id == 0 { - delete(c.PeerExtensionIDs, name) - } else { - if c.PeerExtensionIDs[name] == 0 { - supportedExtensionMessages.Add(name, 1) + if c.PeerExtensionIDs == nil { + c.PeerExtensionIDs = make(map[string]byte, len(mTyped)) + } + for name, v := range mTyped { + id, ok := v.(int64) + if !ok { + log.Printf("bad handshake m item extension ID type: %T", v) + continue + } + if id == 0 { + delete(c.PeerExtensionIDs, name) + } else { + if c.PeerExtensionIDs[name] == 0 { + supportedExtensionMessages.Add(name, 1) + } + c.PeerExtensionIDs[name] = byte(id) } - c.PeerExtensionIDs[name] = byte(id) } } metadata_sizeUntyped, ok := d["metadata_size"]