Browse Source

Don't ask for remote addr if we are full and restrict number of addr from one node

master
Lyndsay Roger 9 years ago
parent
commit
be8b3122f9
  1. 15
      crawler.go
  2. 6
      network.go

15
crawler.go

@ -39,7 +39,7 @@ func crawlNode(s *dnsseeder, nd *node) { @@ -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) { @@ -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) { @@ -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) { @@ -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, @@ -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()

6
network.go

@ -41,7 +41,7 @@ func createNetFile() { @@ -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) { @@ -91,10 +91,12 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
return nil, errors.New(fmt.Sprintf("No DNS Hostname supplied"))
}
// 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))
}

Loading…
Cancel
Save