add opt.validate functions peerIn, peerOut - #1333
Conversation
|
To use just add a validate object to the gun option and any or all of the 2 validate functions and return truthy values to allow or falsy to deny. //for a nodejs server:
const validate = {
peerIn( raw, peer, gunRoot ){
const peerIsRelay = !!peer.url
console.log( `PEER_IN: peerIsRelay ${ peerIsRelay }, ${ peer.wire._socket.remoteAddress }, ${JSON.stringify( peer.id )} - ${raw}\n\r` )
//must return a truthy for gun to accept a message
return true
},
peerOut( raw, peer, wireMessage ){
const peerIsRelay = !peer.wire._socket || !!peer.wire._url
console.log( `PEER_OUT: peerIsRelay ${ peerIsRelay }, ${JSON.stringify( peer.wire?.headers?.host || peer.wire?._url )} - ${raw} \n\r` )
//must return a truthy for gun to send message
return true
},
}
const gunConfig = {
axe: false,
web: config.server.listen(config.port),
peers: process.env?.PEERS?.split(',') || [],
validate,
}
var gun = Gun( gunConfig ); |
|
|
|
@amark it was hard to pick the exact spots to add these validation function, I tried to add them at the lowest level possible so messages could be dropped before much processing has been done. Any feedback to improve it would be great. |
|
I removed validate.dataIn, since on.in and on.put events work just as well. |
|
Oh sorry, GitHub's email notification system has been broken for me for a while. Thanks for contributing :) I disagree with how tho:
Is there something about the above 2 comments that would not solve what you are needing to do? Thank you for jumping in and helping tho! Want to contribute more in other ways too? |
I am adding some validate functions to the base gun code. This will give users custom ability to validate incoming / outgoing traffic, and in the case of validate.dataIn, control whether or not data is stored in the local graph.