| 371 | } |
| 372 | |
| 373 | func (t *tunneler) cache(update tunnel) { |
| 374 | t.mu.Lock() |
| 375 | defer t.mu.Unlock() |
| 376 | if update.active { |
| 377 | if _, ok := t.latest[update.src]; !ok { |
| 378 | t.latest[update.src] = map[uuid.UUID]tunnel{} |
| 379 | } |
| 380 | t.latest[update.src][update.dst] = update |
| 381 | } else { |
| 382 | // If inactive and dst is nil, it means clean up all tunnels. |
| 383 | if update.dst == uuid.Nil { |
| 384 | delete(t.latest, update.src) |
| 385 | } else { |
| 386 | delete(t.latest[update.src], update.dst) |
| 387 | // clean up the tunnel map if all the tunnels are gone. |
| 388 | if len(t.latest[update.src]) == 0 { |
| 389 | delete(t.latest, update.src) |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | // retrieveBinding gets the latest tunnel for a key. |
| 396 | func (t *tunneler) retrieve(k tKey) tunnel { |