本文整理汇总了Golang中github.com/jbenet/go-ipfs/peer.Peer.AddAddress方法的典型用法代码示例。如果您正苦于以下问题:Golang Peer.AddAddress方法的具体用法?Golang Peer.AddAddress怎么用?Golang Peer.AddAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jbenet/go-ipfs/peer.Peer
的用法示例。
在下文中一共展示了Peer.AddAddress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleNewConn
// Handle getting ID from this peer and adding it into the map
func (s *Swarm) handleNewConn(nconn net.Conn) {
p := new(peer.Peer)
conn := &Conn{
Peer: p,
Addr: nil,
Conn: nconn,
}
newConnChans(conn)
sin, sout, err := ident.Handshake(s.local, p, conn.Incoming.MsgChan, conn.Outgoing.MsgChan)
if err != nil {
u.PErr("%v\n", err.Error())
conn.Close()
return
}
// Get address to contact remote peer from
addr := <-sin
maddr, err := ma.NewMultiaddr(string(addr))
if err != nil {
u.PErr("Got invalid address from peer.")
s.Error(err)
return
}
p.AddAddress(maddr)
conn.secIn = sin
conn.secOut = sout
err = s.StartConn(conn)
if err != nil {
s.Error(err)
}
}
示例2: ConnectNew
// ConnectNew is for connecting to a peer when you dont know their ID,
// Should only be used when you are sure that you arent already connected to peer in question
func (s *Swarm) ConnectNew(addr *ma.Multiaddr) (*peer.Peer, error) {
if addr == nil {
return nil, errors.New("nil Multiaddr passed to swarm.Connect()")
}
npeer := new(peer.Peer)
npeer.AddAddress(addr)
conn, err := Dial("tcp", npeer)
if err != nil {
return nil, err
}
err = s.handleDialedCon(conn)
return npeer, err
}
示例3: makePeer
func makePeer(addr *ma.Multiaddr) *peer.Peer {
p := new(peer.Peer)
p.AddAddress(addr)
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
if err != nil {
panic(err)
}
p.PrivKey = sk
p.PubKey = pk
id, err := identify.IDFromPubKey(pk)
if err != nil {
panic(err)
}
p.ID = id
return p
}
示例4: setupDHTS
func setupDHTS(n int, t *testing.T) ([]*ma.Multiaddr, []*peer.Peer, []*IpfsDHT) {
var addrs []*ma.Multiaddr
for i := 0; i < 4; i++ {
a, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", 5000+i))
if err != nil {
t.Fatal(err)
}
addrs = append(addrs, a)
}
var peers []*peer.Peer
for i := 0; i < 4; i++ {
p := new(peer.Peer)
p.AddAddress(addrs[i])
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
if err != nil {
panic(err)
}
p.PubKey = pk
p.PrivKey = sk
id, err := identify.IDFromPubKey(pk)
if err != nil {
panic(err)
}
p.ID = id
peers = append(peers, p)
}
var dhts []*IpfsDHT
for i := 0; i < 4; i++ {
net := swarm.NewSwarm(peers[i])
err := net.Listen()
if err != nil {
t.Fatal(err)
}
d := NewDHT(peers[i], net, ds.NewMapDatastore())
dhts = append(dhts, d)
d.Start()
}
return addrs, peers, dhts
}