func NewIDService(h host.Host) *IDService { s := &IDService{ Host: h, currid: make(map[inet.Conn]chan struct{}), } h.SetStreamHandler(ID, s.RequestHandler) return s }
func NewRelayService(h host.Host, sh inet.StreamHandler) *RelayService { s := &RelayService{ host: h, handler: sh, } h.SetStreamHandler(ID, s.requestHandler) return s }
func testHasProtocolVersions(t *testing.T, h host.Host, p peer.ID) { v, err := h.Peerstore().Get(p, "ProtocolVersion") if v == nil { t.Error("no protocol version") return } if v.(string) != identify.LibP2PVersion { t.Error("protocol mismatch", err) } v, err = h.Peerstore().Get(p, "AgentVersion") if v.(string) != identify.ClientVersion { t.Error("agent version mismatch", err) } }
func testHasPublicKey(t *testing.T, h host.Host, p peer.ID, shouldBe ic.PubKey) { k := h.Peerstore().PubKey(p) if k == nil { t.Error("no public key") return } if !k.Equals(shouldBe) { t.Error("key mismatch") return } p2, err := peer.IDFromPublicKey(k) if err != nil { t.Error("could not make key") } else if p != p2 { t.Error("key does not match peerid") } }
func testKnowsAddrs(t *testing.T, h host.Host, p peer.ID, expected []ma.Multiaddr) { actual := h.Peerstore().Addrs(p) if len(actual) != len(expected) { t.Errorf("expected: %s", expected) t.Errorf("actual: %s", actual) t.Fatal("dont have the same addresses") } have := map[string]struct{}{} for _, addr := range actual { have[addr.String()] = struct{}{} } for _, addr := range expected { if _, found := have[addr.String()]; !found { t.Errorf("%s did not have addr for %s: %s", h.ID(), p, addr) // panic("ahhhhhhh") } } }
func NewPingService(h host.Host) *PingService { ps := &PingService{h} h.SetStreamHandler(ID, ps.PingHandler) return ps }