Skip to content

Commit

Permalink
zmq4: deal with empty identity for ROUTER sockets
Browse files Browse the repository at this point in the history

Co-authored-by: Ziyan <ziyan.zhou@mujin.co.jp>
  • Loading branch information
superfashi and ziyan authored Apr 11, 2023
1 parent 1d9bdfe commit 72ac04f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ type socket struct {
autoReconnect bool

mu sync.RWMutex
ids map[string]*Conn // ZMTP connection IDs
conns []*Conn // ZMTP connections
conns []*Conn // ZMTP connections
r rpool
w wpool

Expand All @@ -69,7 +68,6 @@ func newDefaultSocket(ctx context.Context, sockType SocketType) *socket {
retry: defaultRetry,
maxRetries: defaultMaxRetries,
sec: nullSecurity{},
ids: make(map[string]*Conn),
conns: nil,
r: newQReader(ctx),
w: newMWriter(ctx),
Expand Down Expand Up @@ -279,12 +277,14 @@ func (sck *socket) addConn(c *Conn) {
sck.mu.Lock()
defer sck.mu.Unlock()
sck.conns = append(sck.conns, c)
uuid, ok := c.Peer.Meta[sysSockID]
if !ok {
uuid = newUUID()
c.Peer.Meta[sysSockID] = uuid
if len(c.Peer.Meta[sysSockID]) == 0 {
switch c.typ {
case Router: // TODO: STREAM type when implemented
// if empty Identity metadata is received from some client
// need to assign an uuid such that router socket can reply to the correct client
c.Peer.Meta[sysSockID] = newUUID()
}
}
sck.ids[uuid] = c
if sck.w != nil {
sck.w.addConn(c)
}
Expand Down

0 comments on commit 72ac04f

Please sign in to comment.