Skip to content

Commit

Permalink
Adjust handshake initiation ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
weiiwang01 committed Sep 20, 2023
1 parent 3658b0c commit 217b9d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,6 @@ func MakeWireguardAnalyzer(publicKeys [][]byte) WireguardAnalyzer {
return WireguardAnalyzer{
table: exchange.MakeExchangeTable(),
publicKeys: publicKeys,
filter: bloom.MakeFilter(8*1024*1024, 5, salt),
filter: bloom.MakeFilter(32*1024*1024, 10, salt),
}
}
9 changes: 6 additions & 3 deletions internal/exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (t *ExchangeTable) AddPeerAddr(index uint32, addr net.UDPAddr) error {

t.table[index] = peerInfo{
addr: addr,
ttl: time.Now().Add(4 * time.Minute),
ttl: time.Now().Add(10 * time.Second),
}

slog.Debug("exchange table updated", "entries", len(t.table))
Expand Down Expand Up @@ -113,13 +113,16 @@ func (t *ExchangeTable) LinkPeers(sender, receiver uint32) error {
return fmt.Errorf("failed to link peers: unknown receiver %d", receiver)
}

ttl := time.Now().Add(time.Duration(4) * time.Minute)

s.established = true
s.counterpart = receiver
s.ttl = ttl
t.table[sender] = s

r.established = true
r.counterpart = sender
r.ttl = s.ttl
r.ttl = ttl
t.table[receiver] = r

return nil
Expand All @@ -132,7 +135,7 @@ func (t *ExchangeTable) GetPeerCounterpart(index uint32) (uint32, error) {

peer, ok := t.table[index]
if !ok || !peer.established {
return 0, fmt.Errorf("peer %d has no counterpart", index)
return 0, fmt.Errorf("peer %d doesn't exist or has no counterpart", index)
}

return peer.counterpart, nil
Expand Down

0 comments on commit 217b9d9

Please sign in to comment.