-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add opt.validate functions peerIn, peerOut #1333
base: master
Are you sure you want to change the base?
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.