diff --git a/crawler.go b/crawler.go index c4ba931..550b913 100644 --- a/crawler.go +++ b/crawler.go @@ -39,7 +39,7 @@ func crawlNode(s *dnsseeder, nd *node) { } // connect to the remote ip and ask them for their addr list - rna, e := crawlIP(s.pver, s.id, nd) + rna, e := crawlIP(s.pver, s.id, nd, s.isFull()) if e != nil { // update the fact that we have not connected to this node @@ -99,6 +99,8 @@ func crawlNode(s *dnsseeder, nd *node) { nd.statusStr = "ok: received remote address list" added := 0 + // do not accept more than one third of maxSize addresses from one node + oneThird := int(float64(s.maxSize / 3)) // if we are full then skip adding more possible clients if s.isFull() == false { @@ -106,7 +108,9 @@ func crawlNode(s *dnsseeder, nd *node) { for _, na := range rna { // a new network address so add to the system if x := s.addNa(na); x == true { - added++ + if added++; added > oneThird { + break + } } } } @@ -136,7 +140,7 @@ func crawlEnd(nd *node) { } // crawlIP retrievs a slice of ip addresses from a client -func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node) ([]*wire.NetAddress, *crawlError) { +func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node, full bool) ([]*wire.NetAddress, *crawlError) { ip := nd.na.IP.String() port := strconv.Itoa(int(nd.na.Port)) @@ -221,6 +225,11 @@ func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node) ([]*wire.NetAddress, return nil, &crawlError{"Did not receive expected Ver Ack message from remote client", errors.New("")} } + // if we get this far and if the seeder is full then don't ask for addresses. This will reduce bandwith usage while still + // confirming that we can connect to the remote node + if full { + return nil, nil + } // send getaddr command msgGetAddr := wire.NewMsgGetAddr() diff --git a/network.go b/network.go index 7e7cf7c..a7d6326 100644 --- a/network.go +++ b/network.go @@ -41,7 +41,7 @@ func createNetFile() { Desc: "Description of SeederNet", SeederType: "Combined", Secret: "32bYTesoFSECretThAtiSASecrET!!", - Remote: "ipofdnsserver.example.com:1234", + Remote: "http://dnsserver.example.com:1234/updatedns", Seeder1: "seeder1.example.com", Seeder2: "seed1.bob.com", Seeder3: "seed2.example.com", @@ -91,10 +91,12 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) { return nil, errors.New(fmt.Sprintf("No DNS Hostname supplied")) } - if ok := checkBlockSize(jnw.Secret); ok != true { - return nil, errors.New(fmt.Sprintf("shared secret must be either 16, 24 or 32 bytes long. currently: %v", len(jnw.Secret))) + // we only need a secret if we are a crawler or dns type + if needSecret := convertSeederType(jnw.SeederType); needSecret != typeCombined { + if ok := checkBlockSize(jnw.Secret); ok != true { + return nil, errors.New(fmt.Sprintf("shared secret must be either 16, 24 or 32 bytes long. currently: %v", len(jnw.Secret))) + } } - if _, ok := config.seeders[jnw.Name]; ok { return nil, errors.New(fmt.Sprintf("Name already exists from previous file - %s", jnw.Name)) }