From 4d154b7f0651c02c49cbb0ebe6325bbf0b72feb8 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 8 Dec 2024 16:57:19 +0800 Subject: UID -> CID --- clients.go | 22 +++++++++++----------- errors.go | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clients.go b/clients.go index 0ef95c6..16dea78 100644 --- a/clients.go +++ b/clients.go @@ -10,7 +10,7 @@ import ( type Client struct { conn *net.Conn - UID string + CID string Nick string Ident string Gecos string @@ -46,15 +46,15 @@ func (client Client) ClientSource() string { } func (client Client) ServerSource() string { - return client.UID + return client.CID } func (client *Client) Teardown() { if client.conn != nil { (*client.conn).Close() } - if !uidToClient.CompareAndDelete(client.UID, client) { - slog.Error("uid inconsistent", "uid", client.UID, "client", client) + if !cidToClient.CompareAndDelete(client.CID, client) { + slog.Error("cid inconsistent", "cid", client.CID, "client", client) } if client.State >= ClientStateRegistered || client.Nick != "*" { if !nickToClient.CompareAndDelete(client.Nick, client) { @@ -73,22 +73,22 @@ func NewLocalClient(conn *net.Conn) (*Client, error) { Extra: make(map[string]any), } for range 10 { - uid_ := []byte(self.SID) + cid_ := []byte(self.SID) for range 6 { randint, err := rand.Int(rand.Reader, big.NewInt(26)) if err != nil { return nil, err } - uid_ = append(uid_, byte(65+randint.Uint64())) + cid_ = append(cid_, byte(65+randint.Uint64())) } - uid := string(uid_) - _, exists := uidToClient.LoadOrStore(uid, client) + cid := string(cid_) + _, exists := cidToClient.LoadOrStore(cid, client) if !exists { - client.UID = uid + client.CID = cid return client, nil } } - return nil, ErrUIDBusy + return nil, ErrCIDBusy } func (client *Client) checkRegistration() error { @@ -136,6 +136,6 @@ const ( ) var ( - uidToClient = sync.Map{} + cidToClient = sync.Map{} nickToClient = sync.Map{} ) diff --git a/errors.go b/errors.go index a65fdef..9cd41b5 100644 --- a/errors.go +++ b/errors.go @@ -12,7 +12,7 @@ var ( ErrBodyTooLong = errors.New("body too long") ErrNotConnectedServer = errors.New("not connected server") ErrSendToSelf = errors.New("attempt to send message to self") - ErrUIDBusy = errors.New("too many busy uids") + ErrCIDBusy = errors.New("too many busy cids") ErrCallState = errors.New("invalid call state") ErrInconsistentGlobal = errors.New("inconsistent global state") ErrInconsistentClient = errors.New("inconsistent client state") -- cgit v1.2.3