Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: remove extraneous message size filter (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc authored and vasco-santos committed Nov 28, 2019
1 parent 6b9eba1 commit 58b6b36
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 25 deletions.
2 changes: 0 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ exports.K = 20
// Alpha is the concurrency for asynchronous requests
exports.ALPHA = 3

exports.maxMessageSize = 2 << 22 // 4MB

exports.defaultRandomWalk = {
enabled: true,
queriesPerPeriod: 1,
Expand Down
3 changes: 0 additions & 3 deletions src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ async function writeReadMessage (stream, msg) {
[msg],
lp.encode(),
stream,
utils.itFilter(
(msg) => msg.length < c.maxMessageSize
),
lp.decode(),
async source => {
for await (const chunk of source) {
Expand Down
16 changes: 6 additions & 10 deletions src/rpc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const PeerInfo = require('peer-info')
const Message = require('../message')
const handlers = require('./handlers')
const utils = require('../utils')
const c = require('../constants')

module.exports = (dht) => {
const log = utils.logger(dht.peerInfo.id, 'rpc')
Expand Down Expand Up @@ -63,16 +62,13 @@ module.exports = (dht) => {
lp.decode(),
source => (async function * () {
for await (const msg of source) {
// Check message size
if (msg.length < c.maxMessageSize) {
// handle the message
const desMessage = Message.deserialize(msg.slice())
const res = await handleMessage(peerInfo, desMessage)
// handle the message
const desMessage = Message.deserialize(msg.slice())
const res = await handleMessage(peerInfo, desMessage)

// Not all handlers will return a response
if (res) {
yield res.serialize()
}
// Not all handlers will return a response
if (res) {
yield res.serialize()
}
}
})(),
Expand Down
10 changes: 0 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ const { Record } = require('libp2p-record')
const PeerId = require('peer-id')
const errcode = require('err-code')

exports.itFilter = function (predicate) {
return source => (async function * () {
for await (const msg of source) {
if (predicate(msg)) {
yield msg
}
}
})()
}

/**
* Creates a DHT ID by hashing a given buffer.
*
Expand Down

0 comments on commit 58b6b36

Please sign in to comment.