diff options
Diffstat (limited to 'swarm/network/kademlia')
-rw-r--r-- | swarm/network/kademlia/kaddb.go | 27 | ||||
-rw-r--r-- | swarm/network/kademlia/kademlia.go | 27 |
2 files changed, 26 insertions, 28 deletions
diff --git a/swarm/network/kademlia/kaddb.go b/swarm/network/kademlia/kaddb.go index 53a7db451..f4279917e 100644 --- a/swarm/network/kademlia/kaddb.go +++ b/swarm/network/kademlia/kaddb.go @@ -24,8 +24,7 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" ) type NodeData interface { @@ -88,12 +87,12 @@ func (self *KadDb) findOrCreate(index int, a Address, url string) *NodeRecord { Addr: a, Url: url, } - glog.V(logger.Info).Infof("add new record %v to kaddb", record) + log.Info(fmt.Sprintf("add new record %v to kaddb", record)) // insert in kaddb self.index[a] = record self.Nodes[index] = append(self.Nodes[index], record) } else { - glog.V(logger.Info).Infof("found record %v in kaddb", record) + log.Info(fmt.Sprintf("found record %v in kaddb", record)) } // update last seen time record.setSeen() @@ -121,13 +120,13 @@ func (self *KadDb) add(nrs []*NodeRecord, proximityBin func(Address) int) { copy(newnodes[:], nodes[:dbcursor]) newnodes[dbcursor] = node copy(newnodes[dbcursor+1:], nodes[dbcursor:]) - glog.V(logger.Detail).Infof("new nodes: %v (keys: %v)\nnodes: %v", newnodes, nodes) + log.Trace(fmt.Sprintf("new nodes: %v (keys: %v)\nnodes: %v", newnodes, nodes)) self.Nodes[index] = newnodes n++ } } if n > 0 { - glog.V(logger.Debug).Infof("%d/%d node records (new/known)", n, len(nrs)) + log.Debug(fmt.Sprintf("%d/%d node records (new/known)", n, len(nrs))) } } @@ -207,13 +206,13 @@ func (self *KadDb) findBest(maxBinSize int, binSize func(int) int) (node *NodeRe // skip already connected nodes if node.node != nil { - glog.V(logger.Debug).Infof("kaddb record %v (PO%03d:%d/%d) already connected", node.Addr, po, cursor, len(dbrow)) + log.Debug(fmt.Sprintf("kaddb record %v (PO%03d:%d/%d) already connected", node.Addr, po, cursor, len(dbrow))) continue ROW } // if node is scheduled to connect if time.Time(node.After).After(time.Now()) { - glog.V(logger.Debug).Infof("kaddb record %v (PO%03d:%d) skipped. seen at %v (%v ago), scheduled at %v", node.Addr, po, cursor, node.Seen, delta, node.After) + log.Debug(fmt.Sprintf("kaddb record %v (PO%03d:%d) skipped. seen at %v (%v ago), scheduled at %v", node.Addr, po, cursor, node.Seen, delta, node.After)) continue ROW } @@ -224,17 +223,17 @@ func (self *KadDb) findBest(maxBinSize int, binSize func(int) int) (node *NodeRe if delta > self.purgeInterval { // remove node purge[cursor] = true - glog.V(logger.Debug).Infof("kaddb record %v (PO%03d:%d) unreachable since %v. Removed", node.Addr, po, cursor, node.Seen) + log.Debug(fmt.Sprintf("kaddb record %v (PO%03d:%d) unreachable since %v. Removed", node.Addr, po, cursor, node.Seen)) continue ROW } - glog.V(logger.Debug).Infof("kaddb record %v (PO%03d:%d) ready to be tried. seen at %v (%v ago), scheduled at %v", node.Addr, po, cursor, node.Seen, delta, node.After) + log.Debug(fmt.Sprintf("kaddb record %v (PO%03d:%d) ready to be tried. seen at %v (%v ago), scheduled at %v", node.Addr, po, cursor, node.Seen, delta, node.After)) // scheduling next check interval = time.Duration(delta * time.Duration(self.connRetryExp)) after = time.Now().Add(interval) - glog.V(logger.Debug).Infof("kaddb record %v (PO%03d:%d) selected as candidate connection %v. seen at %v (%v ago), selectable since %v, retry after %v (in %v)", node.Addr, po, cursor, rounds, node.Seen, delta, node.After, after, interval) + log.Debug(fmt.Sprintf("kaddb record %v (PO%03d:%d) selected as candidate connection %v. seen at %v (%v ago), selectable since %v, retry after %v (in %v)", node.Addr, po, cursor, rounds, node.Seen, delta, node.After, after, interval)) node.After = after found = true } // ROW @@ -295,9 +294,9 @@ func (self *KadDb) save(path string, cb func(*NodeRecord, Node)) error { } err = ioutil.WriteFile(path, data, os.ModePerm) if err != nil { - glog.V(logger.Warn).Infof("unable to save kaddb with %v nodes to %v: err", n, path, err) + log.Warn(fmt.Sprintf("unable to save kaddb with %v nodes to %v: err", n, path, err)) } else { - glog.V(logger.Info).Infof("saved kaddb with %v nodes to %v", n, path) + log.Info(fmt.Sprintf("saved kaddb with %v nodes to %v", n, path)) } return err } @@ -338,7 +337,7 @@ func (self *KadDb) load(path string, cb func(*NodeRecord, Node) error) (err erro } self.delete(po, purge) } - glog.V(logger.Info).Infof("loaded kaddb with %v nodes from %v", n, path) + log.Info(fmt.Sprintf("loaded kaddb with %v nodes from %v", n, path)) return } diff --git a/swarm/network/kademlia/kademlia.go b/swarm/network/kademlia/kademlia.go index 87c57cefe..8d731c038 100644 --- a/swarm/network/kademlia/kademlia.go +++ b/swarm/network/kademlia/kademlia.go @@ -23,8 +23,7 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" ) const ( @@ -117,7 +116,7 @@ func (self *Kademlia) DBCount() int { // On is the entry point called when a new nodes is added // unsafe in that node is not checked to be already active node (to be called once) func (self *Kademlia) On(node Node, cb func(*NodeRecord, Node) error) (err error) { - glog.V(logger.Warn).Infof("%v", self) + log.Warn(fmt.Sprintf("%v", self)) defer self.lock.Unlock() self.lock.Lock() @@ -126,11 +125,11 @@ func (self *Kademlia) On(node Node, cb func(*NodeRecord, Node) error) (err error if cb != nil { err = cb(record, node) - glog.V(logger.Detail).Infof("cb(%v, %v) ->%v", record, node, err) + log.Trace(fmt.Sprintf("cb(%v, %v) ->%v", record, node, err)) if err != nil { return fmt.Errorf("unable to add node %v, callback error: %v", node.Addr(), err) } - glog.V(logger.Debug).Infof("add node record %v with node %v", record, node) + log.Debug(fmt.Sprintf("add node record %v with node %v", record, node)) } // insert in kademlia table of active nodes @@ -139,7 +138,7 @@ func (self *Kademlia) On(node Node, cb func(*NodeRecord, Node) error) (err error // TODO: give priority to peers with active traffic if len(bucket) < self.BucketSize { // >= allows us to add peers beyond the bucketsize limitation self.buckets[index] = append(bucket, node) - glog.V(logger.Debug).Infof("add node %v to table", node) + log.Debug(fmt.Sprintf("add node %v to table", node)) self.setProxLimit(index, true) record.node = node self.count++ @@ -159,10 +158,10 @@ func (self *Kademlia) On(node Node, cb func(*NodeRecord, Node) error) (err error } } if replaced == nil { - glog.V(logger.Debug).Infof("all peers wanted, PO%03d bucket full", index) + log.Debug(fmt.Sprintf("all peers wanted, PO%03d bucket full", index)) return fmt.Errorf("bucket full") } - glog.V(logger.Debug).Infof("node %v replaced by %v (idle for %v > %v)", replaced, node, idle, self.MaxIdleInterval) + log.Debug(fmt.Sprintf("node %v replaced by %v (idle for %v > %v)", replaced, node, idle, self.MaxIdleInterval)) replaced.Drop() // actually replace in the row. When off(node) is called, the peer is no longer in the row bucket[pos] = node @@ -195,7 +194,7 @@ func (self *Kademlia) Off(node Node, cb func(*NodeRecord, Node)) (err error) { } record.node = nil self.count-- - glog.V(logger.Debug).Infof("remove node %v from table, population now is %v", node, self.count) + log.Debug(fmt.Sprintf("remove node %v from table, population now is %v", node, self.count)) return } @@ -223,7 +222,7 @@ func (self *Kademlia) setProxLimit(r int, on bool) { self.proxLimit++ curr = len(self.buckets[self.proxLimit]) - glog.V(logger.Detail).Infof("proxbin contraction (size: %v, limit: %v, bin: %v)", self.proxSize, self.proxLimit, r) + log.Trace(fmt.Sprintf("proxbin contraction (size: %v, limit: %v, bin: %v)", self.proxSize, self.proxLimit, r)) } return } @@ -237,7 +236,7 @@ func (self *Kademlia) setProxLimit(r int, on bool) { // self.proxLimit-- self.proxSize += len(self.buckets[self.proxLimit]) - glog.V(logger.Detail).Infof("proxbin expansion (size: %v, limit: %v, bin: %v)", self.proxSize, self.proxLimit, r) + log.Trace(fmt.Sprintf("proxbin expansion (size: %v, limit: %v, bin: %v)", self.proxSize, self.proxLimit, r)) } } @@ -257,7 +256,7 @@ func (self *Kademlia) FindClosest(target Address, max int) []Node { po := self.proximityBin(target) index := po step := 1 - glog.V(logger.Detail).Infof("serving %v nodes at %v (PO%02d)", max, index, po) + log.Trace(fmt.Sprintf("serving %v nodes at %v (PO%02d)", max, index, po)) // if max is set to 0, just want a full bucket, dynamic number min := max @@ -276,7 +275,7 @@ func (self *Kademlia) FindClosest(target Address, max int) []Node { n++ } // terminate if index reached the bottom or enough peers > min - glog.V(logger.Detail).Infof("add %v -> %v (PO%02d, PO%03d)", len(self.buckets[index]), n, index, po) + log.Trace(fmt.Sprintf("add %v -> %v (PO%02d, PO%03d)", len(self.buckets[index]), n, index, po)) if n >= min && (step < 0 || max == 0) { break } @@ -287,7 +286,7 @@ func (self *Kademlia) FindClosest(target Address, max int) []Node { } index += step } - glog.V(logger.Detail).Infof("serve %d (<=%d) nodes for target lookup %v (PO%03d)", n, max, target, po) + log.Trace(fmt.Sprintf("serve %d (<=%d) nodes for target lookup %v (PO%03d)", n, max, target, po)) return r.nodes } |