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
4ea04c23
Commit
4ea04c23
authored
Oct 17, 2018
by
vyzo
Browse files
identify: implement identify push protocol
parent
2b6c3a22
Changes
1
Hide whitespace changes
Inline
Side-by-side
p2p/protocol/identify/id.go
View file @
4ea04c23
...
...
@@ -3,6 +3,7 @@ package identify
import
(
"context"
"sync"
"time"
pb
"github.com/libp2p/go-libp2p/p2p/protocol/identify/pb"
...
...
@@ -23,6 +24,9 @@ var log = logging.Logger("net/identify")
// ID is the protocol.ID of the Identify Service.
const
ID
=
"/ipfs/id/1.0.0"
// IDPush is the protocol.ID of the Identify push protocol
const
IDPush
=
"/ipfs/id/push/1.0.0"
// LibP2PVersion holds the current protocol version for a client running this code
// TODO(jbenet): fix the versioning mess.
const
LibP2PVersion
=
"ipfs/0.1.0"
...
...
@@ -60,6 +64,7 @@ func NewIDService(h host.Host) *IDService {
currid
:
make
(
map
[
inet
.
Conn
]
chan
struct
{}),
}
h
.
SetStreamHandler
(
ID
,
s
.
requestHandler
)
h
.
SetStreamHandler
(
IDPush
,
s
.
pushHandler
)
h
.
Network
()
.
Notify
((
*
netNotifiee
)(
s
))
return
s
}
...
...
@@ -138,6 +143,24 @@ func (ids *IDService) responseHandler(s inet.Stream) {
go
inet
.
FullClose
(
s
)
}
func
(
ids
*
IDService
)
pushHandler
(
s
inet
.
Stream
)
{
ids
.
responseHandler
(
s
)
}
func
(
ids
*
IDService
)
Push
()
{
for
_
,
p
:=
range
ids
.
Host
.
Network
()
.
Peers
()
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
60
*
time
.
Second
)
s
,
err
:=
ids
.
Host
.
NewStream
(
ctx
,
p
,
IDPush
)
cancel
()
if
err
!=
nil
{
log
.
Debugf
(
"error opening push stream: %s"
,
err
.
Error
())
continue
}
ids
.
requestHandler
(
s
)
}
}
func
(
ids
*
IDService
)
populateMessage
(
mes
*
pb
.
Identify
,
c
inet
.
Conn
)
{
// set protocols this node is currently handling
...
...
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