MCPcopy Create free account
hub / github.com/encodeous/nylon / NewIndexForHandshake

Method NewIndexForHandshake

polyamide/device/indextable.go:58–92  ·  view source on GitHub ↗
(peer *Peer, handshake *Handshake)

Source from the content-addressed store, hash-verified

56}
57
58func (table *IndexTable) NewIndexForHandshake(peer *Peer, handshake *Handshake) (uint32, error) {
59 for {
60 // generate random index
61
62 index, err := randUint32()
63 if err != nil {
64 return index, err
65 }
66
67 // check if index used
68
69 table.RLock()
70 _, ok := table.table[index]
71 table.RUnlock()
72 if ok {
73 continue
74 }
75
76 // check again while locked
77
78 table.Lock()
79 _, found := table.table[index]
80 if found {
81 table.Unlock()
82 continue
83 }
84 table.table[index] = IndexTableEntry{
85 peer: peer,
86 handshake: handshake,
87 keypair: nil,
88 }
89 table.Unlock()
90 return index, nil
91 }
92}
93
94func (table *IndexTable) Lookup(id uint32) IndexTableEntry {
95 table.RLock()

Callers 2

CreateMessageResponseMethod · 0.80

Calls 1

randUint32Function · 0.85

Tested by

no test coverage detected