Skip to content
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

Deal with empty Identity for ROUTER socket #140

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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