Beispiel #1
0
func (d *dht) see(key string, x *e3x.Exchange) ([]hashname.H, error) {
	c, err := x.Open(d.prefix+"see", false)
	if err != nil {
		return nil, err
	}
	defer c.Close()

	pkt := &lob.Packet{}
	pkt.Header().SetString("key", key)
	pkt.Header().SetBool("end", true)
	err = c.WritePacket(pkt)
	if err != nil {
		return nil, err
	}

	pkt, err = c.ReadPacket()
	if err != nil {
		return nil, err
	}

	v, _ := pkt.Header().Get("see")
	l, ok := v.([]string)
	if !ok {
		return nil, nil
	}

	h := make([]hashname.H, len(l))
	for i, s := range l {
		h[i] = hashname.H(s)
	}

	return h, nil
}
Beispiel #2
0
func (mod *module) negotiatePaths(x *e3x.Exchange) {
	addrs := e3x.TransportsFromEndpoint(mod.endpoint).LocalAddresses()

	c, err := x.Open("path", false)
	if err != nil {
		return
	}
	defer c.Kill()

	c.SetDeadline(time.Now().Add(1 * time.Minute))

	pkt := &lob.Packet{}
	pkt.Header().Set("paths", addrs)
	if err := c.WritePacket(pkt); err != nil {
		return // ignore
	}

	for {
		_, err := c.ReadPacket()
		if err == io.EOF || err == e3x.ErrTimeout {
			return
		}
		if err != nil {
			return
		}
	}
}
Beispiel #3
0
func (mod *module) peerVia(router *e3x.Exchange, to hashname.H, body *bufpool.Buffer) error {
	ch, err := router.Open("peer", false)
	if err != nil {
		return err
	}
	defer ch.Kill()

	pkt := lob.New(body.RawBytes())
	pkt.Header().SetString("peer", string(to))
	ch.WritePacket(pkt)

	return nil
}
func (mod *module) connect(ex *e3x.Exchange, inner *bufpool.Buffer) error {
	ch, err := ex.Open("connect", false)
	if err != nil {
		return err
	}

	defer ch.Kill()

	err = ch.WritePacket(lob.New(inner.RawBytes()))
	if err != nil {
		return err
	}

	return nil
}