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

Remove extraneous message size filter #156

Merged
merged 1 commit into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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