Esempio n. 1
0
func (mod *module) handlePathRequest(c *e3x.Channel) {
	defer c.Kill()

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

	// decode paths known by peer and add them as candidates
	if header, found := pkt.Header().Get("paths"); found {
		data, err := json.Marshal(header)
		if err != nil {
			return // ignore
		}

		var entries []json.RawMessage
		err = json.Unmarshal(data, &entries)
		if err != nil {
			return // ignore
		}

		for _, entry := range entries {
			addr, err := transports.DecodeAddr(entry)
			if err != nil {
			}
			if err == nil {
				c.Exchange().AddPathCandidate(addr)
			}
		}
	}

	var pipes = c.Exchange().KnownPipes()

	for _, pipe := range pipes {
		pkt := &lob.Packet{}
		pkt.Header().Set("path", pipe.RemoteAddr())
		c.WritePacketTo(pkt, pipe)
	}
}