Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
first passing
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 27, 2016
1 parent 732d8a2 commit c33804e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/connection.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
'use strict'

const debug = require('debug')

const connHandler = require('./default-handler')
const identify = require('./identify')

const log = debug('libp2p:swarm:connection')
log.error = debug('libp2p:swarm:connection:error')

module.exports = function connection (swarm) {
return {
addUpgrade () {},
Expand All @@ -17,6 +22,10 @@ module.exports = function connection (swarm) {

var peerIdForConn

muxedConn.on('end', () => {
conn.end()
})

muxedConn.on('stream', (conn) => {
function gotId () {
if (peerIdForConn) {
Expand All @@ -38,7 +47,7 @@ module.exports = function connection (swarm) {
if (swarm.identify) {
identify.exec(conn, muxedConn, swarm._peerInfo, (err, pi) => {
if (err) {
return console.log('Identify exec failed', err)
return log.error('Identify exec failed', err)
}

peerIdForConn = pi.id
Expand All @@ -49,6 +58,7 @@ module.exports = function connection (swarm) {
swarm.emit('peer-mux-established', pi)

muxedConn.on('close', () => {
log('peer-mux-closed', pi.id.toB58String())
delete swarm.muxedConns[pi.id.toB58String()]
swarm.emit('peer-mux-closed', pi)
})
Expand Down
4 changes: 0 additions & 4 deletions src/default-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ module.exports = function connHandler (protocols, conn) {
ms.addHandler(protocol, protocols[protocol])
})

conn.on('error', (err) => {
log.error(err)
})

ms.handle(conn, (err) => {
if (err) {
log.error(err)
Expand Down
1 change: 1 addition & 0 deletions src/dial.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ module.exports = function dial (swarm) {

muxedConn.on('close', () => {
delete swarm.muxedConns[pi.id.toB58String()]
conn.end()
swarm.emit('peer-mux-closed', pi)
})

Expand Down

0 comments on commit c33804e

Please sign in to comment.