()
| 153 | } |
| 154 | |
| 155 | func (o *Oracle) newSubscriber() (<-chan pb.OracleDelta, int) { |
| 156 | o.Lock() |
| 157 | defer o.Unlock() |
| 158 | var id int |
| 159 | for { |
| 160 | //nolint:gosec // random generator for node id does not require cryptographic precision |
| 161 | id = rand.Int() |
| 162 | if _, has := o.subscribers[id]; !has { |
| 163 | break |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // The channel takes a delta instead of a pointer as the receiver needs to |
| 168 | // modify it by setting the group checksums. Passing a pointer previously |
| 169 | // resulted in a race condition. |
| 170 | ch := make(chan pb.OracleDelta, 1000) |
| 171 | ch <- *o.currentState() // Queue up the full state as the first entry. |
| 172 | o.subscribers[id] = ch |
| 173 | return ch, id |
| 174 | } |
| 175 | |
| 176 | func (o *Oracle) removeSubscriber(id int) { |
| 177 | o.Lock() |
no test coverage detected