Skip to content

Commit

Permalink
addrmgr: Expose method to update services.
Browse files Browse the repository at this point in the history
This exposes a new method named SetServices to the address manager which
can be used to update the services for a known address.  This will be
useful to keep known services up to date.

Backported from Decred.
  • Loading branch information
davecgh committed Sep 21, 2018
1 parent 4d1e1db commit 24e2352
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions addrmgr/addrmanager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2013-2016 The btcsuite developers
// Copyright (c) 2015-2018 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -937,6 +938,25 @@ func (a *AddrManager) Good(addr *wire.NetAddress) {
a.addrNew[newBucket][rmkey] = rmka
}

// SetServices sets the services for the giiven address to the provided value.
func (a *AddrManager) SetServices(addr *wire.NetAddress, services wire.ServiceFlag) {
a.mtx.Lock()
defer a.mtx.Unlock()

ka := a.find(addr)
if ka == nil {
return
}

// Update the services if needed.
if ka.na.Services != services {
// ka.na is immutable, so replace it.
naCopy := *ka.na
naCopy.Services = services
ka.na = &naCopy
}
}

// AddLocalAddress adds na to the list of known local addresses to advertise
// with the given priority.
func (a *AddrManager) AddLocalAddress(na *wire.NetAddress, priority AddressPriority) error {
Expand Down

0 comments on commit 24e2352

Please sign in to comment.