@@ -190,7 +190,7 @@ type RemoteList struct {
190190 // The full list of vpn addresses assigned to this host
191191 vpnAddrs []netip.Addr
192192
193- // A deduplicated set of addresses. Any accessor should lock beforehand.
193+ // A deduplicated set of underlay addresses. Any accessor should lock beforehand.
194194 addrs []netip.AddrPort
195195
196196 // A set of relay addresses. VpnIp addresses that the remote identified as relays.
@@ -201,8 +201,10 @@ type RemoteList struct {
201201 // For learned addresses, this is the vpnIp that sent the packet
202202 cache map [netip.Addr ]* cache
203203
204- hr * hostnamesResults
205- shouldAdd func (netip.Addr ) bool
204+ hr * hostnamesResults
205+
206+ // shouldAdd is a nillable function that decides if x should be added to addrs.
207+ shouldAdd func (vpnAddrs []netip.Addr , x netip.Addr ) bool
206208
207209 // This is a list of remotes that we have tried to handshake with and have returned from the wrong vpn ip.
208210 // They should not be tried again during a handshake
@@ -213,7 +215,7 @@ type RemoteList struct {
213215}
214216
215217// NewRemoteList creates a new empty RemoteList
216- func NewRemoteList (vpnAddrs []netip.Addr , shouldAdd func (netip.Addr ) bool ) * RemoteList {
218+ func NewRemoteList (vpnAddrs []netip.Addr , shouldAdd func ([]netip. Addr , netip.Addr ) bool ) * RemoteList {
217219 r := & RemoteList {
218220 vpnAddrs : make ([]netip.Addr , len (vpnAddrs )),
219221 addrs : make ([]netip.AddrPort , 0 ),
@@ -368,6 +370,15 @@ func (r *RemoteList) CopyBlockedRemotes() []netip.AddrPort {
368370 return c
369371}
370372
373+ // RefreshFromHandshake locks and updates the RemoteList to account for data learned upon a completed handshake
374+ func (r * RemoteList ) RefreshFromHandshake (vpnAddrs []netip.Addr ) {
375+ r .Lock ()
376+ r .badRemotes = nil
377+ r .vpnAddrs = make ([]netip.Addr , len (vpnAddrs ))
378+ copy (r .vpnAddrs , vpnAddrs )
379+ r .Unlock ()
380+ }
381+
371382// ResetBlockedRemotes locks and clears the blocked remotes list
372383func (r * RemoteList ) ResetBlockedRemotes () {
373384 r .Lock ()
@@ -577,7 +588,7 @@ func (r *RemoteList) unlockedCollect() {
577588
578589 dnsAddrs := r .hr .GetAddrs ()
579590 for _ , addr := range dnsAddrs {
580- if r .shouldAdd == nil || r .shouldAdd (addr .Addr ()) {
591+ if r .shouldAdd == nil || r .shouldAdd (r . vpnAddrs , addr .Addr ()) {
581592 if ! r .unlockedIsBad (addr ) {
582593 addrs = append (addrs , addr )
583594 }
0 commit comments