예제 #1
0
func (d *Discoverer) onInterestingNode(node tracker.Node) {
	d.m.Lock()
	defer d.m.Unlock()
	meta, _ := node.Meta()
	uuid := node.UUID()
	d.logger.Println("Found interesting node", string(uuid))
	if p, s := d.nodeSeen(uuid); s {
		p.Send(&messages.HelloOk{})
		d.logger.Println("Node is already known")
		return
	}

	p, err := peer.New(uuid, node.Addr.String(), meta.Adport, d.incoming, d.cfg)
	if err != nil {
		d.logger.Println("ERROR: ", err)
	}
	p.InitConnection()

	if !d.cfg.Exporting() {
		p.Check()
	}

	d.connectedPeers.JoinFuture(p.Connected())
	d.seenNodes[p.UUID()] = p

}
예제 #2
0
func (d *Discoverer) isNodeInteresting(node tracker.Node) bool {

	if d.cfg.Debug() {
		d.logger.Println("Checking if node is interesting")
	}

	meta, err := node.Meta()
	if err != nil {
		if d.cfg.Debug() {
			d.logger.Println("Node meta is corrupt:", err)
		}
		return false
	}

	if meta.Exporting == d.cfg.Exporting() {
		if d.cfg.Debug() {
			d.logger.Println("Node is of same type")
		}
		return false
	}

	tk, tv, err := meta.TagKeyValue()

	if err != nil {
		if d.cfg.Debug() {
			d.logger.Println("Node tags corrupted:", err)
		}
		return false
	}

	// if we are an Input, the Output can have more tags then we, otherwise the sent tag must be part of our tagset

	if !d.cfg.Exporting() {
		return true
	}

	t, f := d.cfg.Tags()[tk]
	if d.cfg.Debug() {
		d.logger.Println("Node tag is not in tagset")
	}
	if !f {
		return false
	}

	if t != tv {
		if d.cfg.Debug() {
			d.logger.Println("Node tag is not in tagset")
		}
		return false
	}

	return true
}