Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
1eb31086
Commit
1eb31086
authored
Jun 10, 2016
by
Jeromy
Browse files
some fixes to make things work with js a little better
parent
97e67744
Changes
6
Hide whitespace changes
Inline
Side-by-side
p2p/net/conn/conn.go
View file @
1eb31086
...
...
@@ -128,6 +128,10 @@ func (c *singleConn) Write(buf []byte) (int, error) {
return
c
.
maconn
.
Write
(
buf
)
}
func
(
c
*
singleConn
)
SetRemotePeer
(
id
peer
.
ID
)
{
c
.
remote
=
id
}
// ID returns the ID of a given Conn.
func
ID
(
c
Conn
)
string
{
l
:=
fmt
.
Sprintf
(
"%s/%s"
,
c
.
LocalMultiaddr
(),
c
.
LocalPeer
()
.
Pretty
())
...
...
p2p/net/conn/interface.go
View file @
1eb31086
...
...
@@ -24,6 +24,7 @@ type PeerConn interface {
RemotePeer
()
peer
.
ID
RemotePublicKey
()
ic
.
PubKey
RemoteMultiaddr
()
ma
.
Multiaddr
SetRemotePeer
(
peer
.
ID
)
}
// Conn is a generic message-based Peer-to-Peer connection.
...
...
p2p/net/conn/secure_conn.go
View file @
1eb31086
...
...
@@ -122,3 +122,7 @@ func (c *secureConn) Write(buf []byte) (int, error) {
func
(
c
*
secureConn
)
ReleaseMsg
(
m
[]
byte
)
{
c
.
secure
.
ReadWriter
()
.
ReleaseMsg
(
m
)
}
func
(
c
*
secureConn
)
SetRemotePeer
(
id
peer
.
ID
)
{
c
.
insecure
.
SetRemotePeer
(
id
)
}
p2p/net/mock/mock_conn.go
View file @
1eb31086
...
...
@@ -147,3 +147,7 @@ func (c *conn) RemotePeer() peer.ID {
func
(
c
*
conn
)
RemotePublicKey
()
ic
.
PubKey
{
return
c
.
remotePubKey
}
func
(
c
*
conn
)
SetRemotePeer
(
id
peer
.
ID
)
{
c
.
remote
=
id
}
p2p/net/swarm/swarm_conn.go
View file @
1eb31086
...
...
@@ -91,6 +91,10 @@ func (c *Conn) Close() error {
return
c
.
StreamConn
()
.
Close
()
}
func
(
c
*
Conn
)
SetRemotePeer
(
id
peer
.
ID
)
{
c
.
RawConn
()
.
SetRemotePeer
(
id
)
}
func
wrapConn
(
psc
*
ps
.
Conn
)
(
*
Conn
,
error
)
{
// grab the underlying connection.
if
_
,
ok
:=
psc
.
NetConn
()
.
(
conn
.
Conn
);
!
ok
{
...
...
p2p/protocol/identify/id.go
View file @
1eb31086
package
identify
import
(
"fmt"
"strings"
"sync"
semver
"github.com/coreos/go-semver/semver"
ggio
"github.com/gogo/protobuf/io"
ci
"github.com/ipfs/go-libp2p-crypto"
"github.com/ipfs/go-libp2p-peer"
pstore
"github.com/ipfs/go-libp2p-peerstore"
host
"github.com/ipfs/go-libp2p/p2p/host"
mstream
"github.com/ipfs/go-libp2p/p2p/metrics/stream"
...
...
@@ -150,6 +153,16 @@ func (ids *IDService) populateMessage(mes *pb.Identify, c inet.Conn) {
mes
.
Protocols
[
i
]
=
string
(
p
)
}
if
c
.
RemotePeer
()
==
""
{
pubk
:=
ids
.
Host
.
Peerstore
()
.
PubKey
(
ids
.
Host
.
ID
())
data
,
err
:=
pubk
.
Bytes
()
if
err
!=
nil
{
log
.
Error
(
"marshaling our public key: "
,
err
)
}
else
{
mes
.
PublicKey
=
data
}
}
// observed address so other side is informed of their
// "public" address, at least in relation to us.
mes
.
ObservedAddr
=
c
.
RemoteMultiaddr
()
.
Bytes
()
...
...
@@ -169,9 +182,35 @@ func (ids *IDService) populateMessage(mes *pb.Identify, c inet.Conn) {
mes
.
AgentVersion
=
&
av
}
func
checkPubKeyID
(
mes
*
pb
.
Identify
,
c
inet
.
Conn
)
error
{
if
len
(
mes
.
PublicKey
)
==
0
{
return
fmt
.
Errorf
(
"remote peer has no ID and no public key was sent"
)
}
pubk
,
err
:=
ci
.
UnmarshalPublicKey
(
mes
.
PublicKey
)
if
err
!=
nil
{
return
err
}
pid
,
err
:=
peer
.
IDFromPublicKey
(
pubk
)
if
err
!=
nil
{
return
err
}
c
.
SetRemotePeer
(
pid
)
return
nil
}
func
(
ids
*
IDService
)
consumeMessage
(
mes
*
pb
.
Identify
,
c
inet
.
Conn
)
{
p
:=
c
.
RemotePeer
()
if
p
==
""
{
err
:=
checkPubKeyID
(
mes
,
c
)
if
err
!=
nil
{
log
.
Warning
(
"no peerID set: "
,
err
)
}
}
// mes.Protocols
// mes.ObservedAddr
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment