mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
connmgr: Accept DNS seeds as string slice.
This modifies the SeedFromDNS function to accept a string of the DNS seeds as well as the default port instead of a concrete chaincfg.Params to remove the tight coupling between the two packages at the API boundary and allow callers to easily provide custom values if desired.
This commit is contained in:
parent
8801d9fa3a
commit
900bbf14ef
@ -3,7 +3,6 @@ module github.com/decred/dcrd/connmgr
|
||||
go 1.11
|
||||
|
||||
require (
|
||||
github.com/decred/dcrd/chaincfg v1.5.2
|
||||
github.com/decred/dcrd/wire v1.2.0
|
||||
github.com/decred/slog v1.0.0
|
||||
)
|
||||
|
||||
@ -1,16 +1,9 @@
|
||||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dchest/blake256 v1.0.0 h1:6gUgI5MHdz9g0TdrgKqXsoDX+Zjxmm1Sc6OsoGru50I=
|
||||
github.com/dchest/blake256 v1.0.0/go.mod h1:xXNWCE1jsAP8DAjP+rKw2MbeqLczjI3TRx2VK+9OEYY=
|
||||
github.com/decred/dcrd/chaincfg v1.5.2 h1:dd6l9rqcpxg2GF5neBmE2XxRc5Lqda45fWmN4XOJRW8=
|
||||
github.com/decred/dcrd/chaincfg v1.5.2/go.mod h1:FukMzTjkwzjPU+hK7CqDMQe3NMbSZAYU5PAcsx1wlv0=
|
||||
github.com/decred/dcrd/chaincfg/chainhash v1.0.1 h1:0vG7U9+dSjSCaHQKdoSKURK2pOb47+b+8FK5q4+Je7M=
|
||||
github.com/decred/dcrd/chaincfg/chainhash v1.0.1/go.mod h1:OVfvaOsNLS/A1y4Eod0Ip/Lf8qga7VXCQjUQLbkY0Go=
|
||||
github.com/decred/dcrd/dcrec/edwards v1.0.0/go.mod h1:HblVh1OfMt7xSxUL1ufjToaEvpbjpWvvTAUx4yem8BI=
|
||||
github.com/decred/dcrd/dcrec/secp256k1 v1.0.1/go.mod h1:lhu4eZFSfTJWUnR3CFRcpD+Vta0KUAqnhTsTksHXgy0=
|
||||
github.com/decred/dcrd/wire v1.2.0 h1:HqJVB7vcklIguzFWgRXw/WYCQ9cD3bUC5TKj53i1Hng=
|
||||
github.com/decred/dcrd/wire v1.2.0/go.mod h1:/JKOsLInOJu6InN+/zH5AyCq3YDIOW/EqcffvU8fJHM=
|
||||
github.com/decred/slog v1.0.0 h1:Dl+W8O6/JH6n2xIFN2p3DNjCmjYwvrXsjlSJTQQ4MhE=
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
// Copyright (c) 2016 The btcsuite developers
|
||||
// Copyright (c) 2019 The Decred developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
@ -8,10 +9,8 @@ import (
|
||||
"fmt"
|
||||
mrand "math/rand"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/decred/dcrd/chaincfg"
|
||||
"github.com/decred/dcrd/wire"
|
||||
)
|
||||
|
||||
@ -23,20 +22,18 @@ const (
|
||||
)
|
||||
|
||||
// OnSeed is the signature of the callback function which is invoked when DNS
|
||||
// seeding is succesfull.
|
||||
// seeding is successful.
|
||||
type OnSeed func(addrs []*wire.NetAddress)
|
||||
|
||||
// LookupFunc is the signature of the DNS lookup function.
|
||||
type LookupFunc func(string) ([]net.IP, error)
|
||||
|
||||
// SeedFromDNS uses DNS seeding to populate the address manager with peers.
|
||||
func SeedFromDNS(chainParams *chaincfg.Params, reqServices wire.ServiceFlag, lookupFn LookupFunc, seedFn OnSeed) {
|
||||
for _, dnsseed := range chainParams.DNSSeeds {
|
||||
var host string
|
||||
if !dnsseed.HasFiltering || reqServices == wire.SFNodeNetwork {
|
||||
host = dnsseed.Host
|
||||
} else {
|
||||
host = fmt.Sprintf("x%x.%s", uint64(reqServices), dnsseed.Host)
|
||||
func SeedFromDNS(dnsSeeds []string, defaultPort uint16, reqServices wire.ServiceFlag, lookupFn LookupFunc, seedFn OnSeed) {
|
||||
for _, seed := range dnsSeeds {
|
||||
host := seed
|
||||
if reqServices != wire.SFNodeNetwork {
|
||||
host = fmt.Sprintf("x%x.%s", uint64(reqServices), seed)
|
||||
}
|
||||
|
||||
go func(host string) {
|
||||
@ -56,7 +53,6 @@ func SeedFromDNS(chainParams *chaincfg.Params, reqServices wire.ServiceFlag, loo
|
||||
}
|
||||
addresses := make([]*wire.NetAddress, len(seedpeers))
|
||||
// if this errors then we have *real* problems
|
||||
intPort, _ := strconv.Atoi(chainParams.DefaultPort)
|
||||
for i, peer := range seedpeers {
|
||||
addresses[i] = wire.NewNetAddressTimestamp(
|
||||
// bitcoind seeds with addresses from
|
||||
@ -64,7 +60,7 @@ func SeedFromDNS(chainParams *chaincfg.Params, reqServices wire.ServiceFlag, loo
|
||||
// and 7 days ago.
|
||||
time.Now().Add(-1*time.Second*time.Duration(secondsIn3Days+
|
||||
randSource.Int31n(secondsIn4Days))),
|
||||
0, peer, uint16(intPort))
|
||||
0, peer, defaultPort)
|
||||
}
|
||||
|
||||
seedFn(addresses)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user