Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions gun.js
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,10 @@
var S = peer.SH = +new Date;
var tmp = raw[0], msg;
//raw && raw.slice && console.log("hear:", ((peer.wire||'').headers||'').origin, raw.length, raw.slice && raw.slice(0,50)); //tc-iamunique-tc-package-ds1
if( opt.validate && opt.validate.peerIn && !opt.validate.peerIn( raw, peer, root ) ){
return mesh.say({ dam: '!', err: "Message invalid."}, peer)
}

if('[' === tmp){
parse(raw, function(err, msg){
if(err || !msg){ return mesh.say({dam: '!', err: "DAM JSON parse error."}, peer) }
Expand Down Expand Up @@ -1548,6 +1552,9 @@
if(id === peer.last){ return } peer.last = id; // was it just sent?
if(peer === meta.via){ return false } // don't send back to self.
if((tmp = meta.yo) && (tmp[peer.url] || tmp[peer.pid] || tmp[peer.id]) /*&& !o*/){ return false }
if( opt.validate && opt.validate.peerOut && !opt.validate.peerOut( raw, peer, msg ) ){
return false
}
console.STAT && console.STAT(S, ((DBG||meta).yp = +new Date) - (meta.y || S), 'say prep');
!loop && ack && dup_track(ack); // streaming long responses needs to keep alive the ack.
if(peer.batch){
Expand Down