| 289 | } |
| 290 | |
| 291 | func (table *AllowedIPs) Insert(prefix netip.Prefix, peer *Peer) { |
| 292 | table.mutex.Lock() |
| 293 | defer table.mutex.Unlock() |
| 294 | |
| 295 | if prefix.Addr().Is6() { |
| 296 | ip := prefix.Addr().As16() |
| 297 | parentIndirection{&table.IPv6, 2}.insert(ip[:], uint8(prefix.Bits()), peer) |
| 298 | } else if prefix.Addr().Is4() { |
| 299 | ip := prefix.Addr().As4() |
| 300 | parentIndirection{&table.IPv4, 2}.insert(ip[:], uint8(prefix.Bits()), peer) |
| 301 | } else { |
| 302 | panic(errors.New("inserting unknown address type")) |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | func (table *AllowedIPs) Lookup(ip []byte) *Peer { |
| 307 | table.mutex.RLock() |