本文整理汇总了Golang中github.com/ipfs/go-libp2p/p2p/host.Host类的典型用法代码示例。如果您正苦于以下问题:Golang Host类的具体用法?Golang Host怎么用?Golang Host使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Host类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewIDService
func NewIDService(h host.Host) *IDService {
s := &IDService{
Host: h,
currid: make(map[inet.Conn]chan struct{}),
}
h.SetStreamHandler(ID, s.RequestHandler)
return s
}
开发者ID:harlantwood,项目名称:go-libp2p,代码行数:8,代码来源:id.go
示例2: NewRelayService
func NewRelayService(h host.Host, sh inet.StreamHandler) *RelayService {
s := &RelayService{
host: h,
handler: sh,
}
h.SetStreamHandler(ID, s.requestHandler)
return s
}
开发者ID:wemeetagain,项目名称:go-libp2p,代码行数:8,代码来源:relay.go
示例3: testHasProtocolVersions
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)
}
}
开发者ID:harlantwood,项目名称:go-libp2p,代码行数:14,代码来源:id_test.go
示例4: getDialableListenAddrs
func getDialableListenAddrs(ph host.Host) ([]*net.TCPAddr, error) {
var out []*net.TCPAddr
for _, addr := range ph.Addrs() {
na, err := manet.ToNetAddr(addr)
if err != nil {
continue
}
tcp, ok := na.(*net.TCPAddr)
if ok {
out = append(out, tcp)
}
}
if len(out) == 0 {
return nil, errors.New("failed to find good external addr from peerhost")
}
return out, nil
}
开发者ID:harlantwood,项目名称:go-libp2p,代码行数:17,代码来源:mdns.go
示例5: testKnowsAddrs
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.Error("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")
}
}
}
开发者ID:harlantwood,项目名称:go-libp2p,代码行数:18,代码来源:id_test.go
示例6: NewMdnsService
func NewMdnsService(peerhost host.Host, interval time.Duration) (Service, error) {
// TODO: dont let mdns use logging...
golog.SetOutput(ioutil.Discard)
var ipaddrs []net.IP
port := 4001
addrs, err := getDialableListenAddrs(peerhost)
if err != nil {
log.Warning(err)
} else {
port = addrs[0].Port
for _, a := range addrs {
ipaddrs = append(ipaddrs, a.IP)
}
}
myid := peerhost.ID().Pretty()
info := []string{myid}
service, err := mdns.NewMDNSService(myid, ServiceTag, "", "", port, ipaddrs, info)
if err != nil {
return nil, err
}
// Create the mDNS server, defer shutdown
server, err := mdns.NewServer(&mdns.Config{Zone: service})
if err != nil {
return nil, err
}
s := &mdnsService{
server: server,
service: service,
host: peerhost,
interval: interval,
}
go s.pollForEntries()
return s, nil
}
开发者ID:harlantwood,项目名称:go-libp2p,代码行数:43,代码来源:mdns.go
示例7: NewPingService
func NewPingService(h host.Host) *PingService {
ps := &PingService{h}
h.SetStreamHandler(ID, ps.PingHandler)
return ps
}
开发者ID:wemeetagain,项目名称:go-libp2p,代码行数:5,代码来源:ping.go
注:本文中的github.com/ipfs/go-libp2p/p2p/host.Host类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论