Skip to content

Commit 306b01c

Browse files
committed
Merge pull request libp2p#6 from diasdavid/last-seen
Add/update a `lastSeen` `Date` object when a stream is opened
2 parents b08107d + 02e0799 commit 306b01c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/swarm.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Swarm () {
1919
}
2020

2121
self.port = parseInt(process.env.IPFS_SWARM_PORT, 10) || 4001
22-
self.connections = {} // {conn: <>, socket: <>}
22+
self.connections = {} // {peerIdB58: {conn: <>, socket: <>}
2323
self.handles = []
2424

2525
// set the listener
@@ -128,6 +128,7 @@ function Swarm () {
128128
msi.handle(stream, function () {
129129
msi.select(protocol, function (err, ds) {
130130
if (err) { return cb(err) }
131+
peer.lastSeen = new Date()
131132
cb(null, ds) // return the stream
132133
})
133134
})

tests/swarm-test.js

+12
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ experiment('BASE', function () {
7272
})
7373
})
7474
})
75+
test('Check for lastSeen', function (done) {
76+
var protocol = '/sparkles/3.3.3'
77+
78+
swarmB.registerHandler(protocol, function (stream) {})
79+
80+
swarmA.openStream(peerB, protocol, function (err, stream) {
81+
expect(err).to.not.be.instanceof(Error)
82+
expect(peerB.lastSeen).to.be.instanceof(Date)
83+
done()
84+
})
85+
})
86+
7587
})
7688

7789
experiment('IDENTIFY', function () {

0 commit comments

Comments
 (0)