Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should accept peer with ip as long', () => {
const __peer = peer.accept({ ip: ip.toLong(prefixedPeer.ip) });
return expect(__peer.ip).to.equal(prefixedPeer.ip);
});
});
}, function (err) {
if (err) {
console.log(err, peer);
return setImmediate(cb, "Invalid peer: " + err);
}
peer.ip = parseInt(peer.ip);
if (isNaN(peer.ip)) {
return setImmediate(cb);
}
if (ip.toLong("127.0.0.1") === peer.ip || peer.port === 0 || peer.port > 65535) {
return setImmediate(cb);
}
self.update(peer, cb);
});
}, cb);
that.contains = function(addr) {
if (!tree) return false;
if (typeof addr !== 'number') addr = ip.toLong(addr);
return tree.contains(addr);
};
//modif
});
//First 8 indexes and last index are reserved in static ip mechanism.
for (let k = 0; k < offSetSize; k++) {
for (let x = 0; x < subnets.length; x++) {
const systemIp = ip.fromLong(ip.toLong(subnets[x].subnetInfo.networkAddress) + k);
ipReservedForSystem[systemIp] = {
instanceId: 'System',
subnet_range: subnets[x].range
};
}
}
const capacity = (NetworkSegmentIndex.capacity() + 1) * segmentation.size;
//push in last segment ip address.
for (let k = capacity; k < capacity + segmentation.size; k++) {
for (let x = 0; x < subnets.length; x++) {
const systemIp = ip.fromLong(ip.toLong(subnets[x].subnetInfo.networkAddress) + k);
ipReservedForSystem[systemIp] = {
instanceId: 'System',
subnet_range: subnets[x].range
};
}
}
logger.info('Ips reserved by current system offsets - ', ipReservedForSystem);
return ipReservedForSystem;
}
}
exports.createUDPFrame = function (target, data, frame) {
var buff = new SmartBuffer();
buff.writeUInt16BE(0);
buff.writeUInt8(frame || 0x00);
if (net.isIPv4(target.host)) {
buff.writeUInt8(0x01);
buff.writeUInt32BE(ip.toLong(target.host));
} else if (net.isIPv6(target.host)) {
buff.writeUInt8(0x04);
buff.writeBuffer(ip.toBuffer(target.host));
} else {
buff.writeUInt8(0x03);
buff.writeUInt8(Buffer.byteLength(target.host));
buff.writeString(target.host);
}
buff.writeUInt16BE(target.port);
buff.writeBuffer(data);
return buff.toBuffer();
};
})();
async.eachSeries(dappConfig.peers, function (peer, cb) {
modules.peer.addDapp({
ip: ip.toLong(peer.ip),
port: peer.port,
dappid: dapp.transactionId
}, cb);
}, function (err) {
if (err) {
function getServers () {
var interfaces = os.networkInterfaces()
var result = []
for (var key in interfaces) {
var addresses = interfaces[key]
for (var i = addresses.length; i--;) {
var address = addresses[i]
if (address.family === 'IPv4' && !address.internal) {
var subnet = ip.subnet(address.address, address.netmask)
var current = ip.toLong(subnet.firstAddress)
var last = ip.toLong(subnet.lastAddress) - 1
while (current++ < last) result.push(ip.fromLong(current))
}
}
}
return result
}
async.eachSeries(dappConfig.peers, function (peer, cb) {
modules.peer.addDapp({
ip: ip.toLong(peer.ip),
port: peer.port,
dappId: dapp.transactionId
}, cb);
}, function (err) {
if (err) {
function isIpWhitelisted(addr, whitelist) {
/*
* if the whitelist passed is not defined or it is not an array, assume
* that the ip address is whitelisted
*/
if (!Array.isArray(whitelist)) {
return true;
}
const thisAddr = ip.toLong(addr);
const ok = whitelist.some((range) => {
if (Array.isArray(range) && range.length === 2) {
const lo = ip.toLong(range[0]);
const hi = ip.toLong(range[1]);
if (lo <= hi && thisAddr >= lo && thisAddr <= hi) {
return true;
}
}
return false;
});
if (ok) {
return ok;
}
if (err) return next(err);
if (!report.isValid) return res.status(500).send({success: false, error: report.issues});
if (req.headers['magic'] !== library.config.magic) {
return res.status(500).send({
success: false,
error: "Request is made on the wrong network",
expected: library.config.magic,
received: req.headers['magic']
});
}
if (peerIp == "127.0.0.1") {
return next();
}
var peer = {
ip: ip.toLong(peerIp),
port: headers.port,
state: 2,
os: headers.os,
version: headers.version
};
if (req.body && req.body.dappid) {
peer.dappid = req.body.dappid;
}
if (peer.port && peer.port > 0 && peer.port <= 65535) {
if (modules.peer.isCompatible(peer.version)) {
peer.version && modules.peer.update(peer);
} else {
return res.status(500).send({
success: false,