Skip to content

Commit ecaefb0

Browse files
committed
fix: change repeated to optional
1 parent 9a15142 commit ecaefb0

File tree

7 files changed

+19
-81
lines changed

7 files changed

+19
-81
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
"author": "",
1919
"license": "ISC",
2020
"dependencies": {
21+
"chai-checkmark": "^1.0.1",
2122
"dgram": "^1.0.1",
2223
"ipaddr.js": "^1.7.0",
2324
"nat-pmp": "^1.0.0",
2425
"nat-upnp": "^1.1.1",
25-
"network": "^0.4.1"
26+
"network": "^0.4.1",
27+
"sinon": "^5.0.10"
2628
},
2729
"devDependencies": {
2830
"aegir": "^13.1.0",

requirements.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Requirements
22

3-
- mapper should be able to hold multiple mappings for the same external
4-
port but different external ips
3+
- mapper should be able to hold multiple mappings for the same external port but different external ips
54
- for example, if the client moves around (laptops, mobile devices) and connects
65
from different access points, the mapper should be able to detect if we're using
76
a different external ip/getaway for which we don't have a prior mapping and add one

src/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ class NatManager extends EE {
2828
ttl,
2929
(err, mapping) => {
3030
if (err) {
31-
return callback(err)
31+
return cb(err)
3232
}
3333

3434
const mapKey = `${mapping.externalIp}:${mapping.externalPort}`
3535
this.activeMappings[mapKey] = mapper
36-
callback(null, mapping)
36+
cb(null, mapping)
3737
})
3838
}
39-
}))
39+
}), callback)
4040
}
4141

4242
deleteMapping (extPort, extIp, callback) {
@@ -52,7 +52,7 @@ class NatManager extends EE {
5252
(ip, cb) => {
5353
const mapper = this.activeMappings[`${ip}:${extPort}`]
5454
if (mapper) {
55-
mapper.deleteMapping(extPort, callback)
55+
mapper.deleteMapping(extPort, cb)
5656
}
5757
}
5858
], callback)
@@ -62,6 +62,10 @@ class NatManager extends EE {
6262
network.get_public_ip(callback)
6363
}
6464

65+
getGwIp (callback) {
66+
network.get_gateway_ip(callback)
67+
}
68+
6569
close (callback) {
6670
parallel(Object.keys(this.activeMappings).map((key) => {
6771
const [ip, port] = key.split(':')

src/mappers/mapper.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/mappers/pmp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const natPmp = require('nat-pmp')
44
const waterfall = require('async/waterfall')
55
const network = require('network')
66

7-
const Mapper = require('./mapper')
7+
const Mapper = require('./')
88

99
class NatPMP extends Mapper {
1010
constructor () {
@@ -20,7 +20,7 @@ class NatPMP extends Mapper {
2020
* @param {Function} callback
2121
* @returns {undefined}
2222
*/
23-
createMapping (intPort, extPort, ttl, callback) {
23+
_addPortMapping (intPort, extPort, ttl, callback) {
2424
network.get_active_interface((err, activeIf) => {
2525
if (err) {
2626
return callback(err)
@@ -65,7 +65,7 @@ class NatPMP extends Mapper {
6565
})
6666
}
6767

68-
_internalDeleteMapping (intPort, extPort, callback) {
68+
_removePortMapping (intPort, extPort, callback) {
6969
network.get_gateway_ip((err, routerIp) => {
7070
if (err) {
7171
return callback(err)

src/mappers/upnp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const natUpnp = require('nat-upnp')
44
const waterfall = require('async/waterfall')
55
const network = require('network')
66

7-
const Mapper = require('./mapper')
7+
const Mapper = require('./')
88

99
class NatPMP extends Mapper {
1010
constructor () {
@@ -20,7 +20,7 @@ class NatPMP extends Mapper {
2020
* @param {Function} callback
2121
* @returns {undefined}
2222
*/
23-
createMapping (intPort, extPort, ttl, callback) {
23+
_addPortMapping (intPort, extPort, ttl, callback) {
2424
network.get_active_interface((err, activeIf) => {
2525
if (err) {
2626
return callback(err)
@@ -64,7 +64,7 @@ class NatPMP extends Mapper {
6464
})
6565
}
6666

67-
_internalDeleteMapping (intPort, extPort, callback) {
67+
_removePortMapping (intPort, extPort, callback) {
6868
const client = natUpnp.createClient()
6969
client.portUnmapping({
7070
public: extPort

test/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict'
22

3+
require('./manager')
34
require('./pmp')
45
require('./upnp')

0 commit comments

Comments
 (0)