Exemplo n.º 1
0
func (i *Identity) UnmarshalJSON(p []byte) error {
	var jsonAddr struct {
		Hashname hashname.H        `json:"hashname"`
		Keys     cipherset.Keys    `json:"keys"`
		Parts    cipherset.Parts   `json:"parts"`
		Addrs    []json.RawMessage `json:"paths"`
	}
	err := json.Unmarshal(p, &jsonAddr)
	if err != nil {
		return err
	}

	var addrs []net.Addr
	for _, m := range jsonAddr.Addrs {
		addr, err := transports.DecodeAddr(m)
		if err != nil {
			return err
		}

		addrs = append(addrs, addr)
	}

	b, err := NewIdentity(jsonAddr.Keys, jsonAddr.Parts, addrs)
	if err != nil {
		return err
	}

	*i = *b
	return nil
}
Exemplo n.º 2
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)
	}
}