diff --git a/dist/bundle-core.js b/dist/bundle-core.js index 6e519e5..78bed75 100644 --- a/dist/bundle-core.js +++ b/dist/bundle-core.js @@ -2820,7 +2820,7 @@ module.exports= },{}],595:[function(require,module,exports){ -var isFeed=require("ssb-ref").isFeed,DuplexPair=require("pull-pair/duplex");function ErrorDuplex(n){var e=new Error(n);return{source:function(n,t){t(e)},sink:function(n){n(e,function(){})}}}function isObject(n){return"object"==typeof n}function noop(){}exports.name="tunnel",exports.version=require("./package.json").version,exports.manifest={announce:"sync",connect:"duplex",ping:"sync"},exports.permissions={anonymous:{allow:["connect","announce","ping"]}},exports.init=function(n,e){var t,r={},o=e.tunnel&&e.tunnel.logging;function i(n){o&&console.error(n)}function u(n){var e;if(isObject(n))e=n;else{var t=n.split(":");if("tunnel"!=t[0])return;e={name:t[0],portal:t[1],target:t[2],instance:+t[3]||0}}if("tunnel"===e.name&&isFeed(e.portal)&&isFeed(e.target)&&Number.isInteger(e.instance))return e}n.multiserver.transport({name:"tunnel",create:function(e){var r=e.portal,o=e.instance||0;return{name:"tunnel",scope:function(){return e.scope},server:function(n){t=n},client:function(e,t){var r=u(e);i("tunnel:connect - connect to portal:"+r.portal),n.gossip.connect(r.portal,function(e,o){e?(i("tunnel:connect - failed connect to portal:"+r.portal+" "+e.message),t(e)):(i("tunnel:connect - portal connected, tunnel to target:"+r.target),t(null,o.tunnel.connect({target:r.target,instance:r.instance,origin:n.id},noop)))})},parse:u,stringify:function(){if(r)return["tunnel",r,n.id,o].join(":")}}}});var c=null;return{setupIsConnectionOkHandler:function(n){c=n},announce:function(e){i("tunnel:portal - received endpoint announcement from:"+this.id),r[this.id]=n.peers[this.id][0]},connect:function(e){if(!e)return ErrorDuplex("opts *must* be provided");if(console.log("tunnel connect, target",e.target),r[e.target])return i("tunnel:portal - received tunnel request for target:"+e.target+", from:"+this.id),r[e.target].tunnel.connect(e,noop);if(e.target===n.id){function o(){var n=DuplexPair();return n[0].address="tunnel:@"+SSB.remoteAddress.split(":")[3]+":"+e.origin,t(n[0]),n[1]}return c?c(e.origin)?o():ErrorDuplex("not allowed to connect"):o()}return ErrorDuplex("could not connect to:"+e.target)},ping:function(){return Date.now()}}}; +var isFeed=require("ssb-ref").isFeed,DuplexPair=require("pull-pair/duplex");function ErrorDuplex(n){var e=new Error(n);return{source:function(n,t){t(e)},sink:function(n){n(e,function(){})}}}function isObject(n){return"object"==typeof n}function noop(){}exports.name="tunnel",exports.version=require("./package.json").version,exports.manifest={announce:"sync",connect:"duplex",ping:"sync"},exports.permissions={anonymous:{allow:["connect","announce","ping"]}},exports.init=function(n,e){var t,r={},o=e.tunnel&&e.tunnel.logging;function i(n){o&&console.error(n)}function u(n){var e;if(isObject(n))e=n;else{var t=n.split(":");if("tunnel"!=t[0])return;e={name:t[0],portal:t[1],target:t[2],instance:+t[3]||0}}if("tunnel"===e.name&&isFeed(e.portal)&&isFeed(e.target)&&Number.isInteger(e.instance))return e}n.multiserver.transport({name:"tunnel",create:function(e){var r=e.portal,o=e.instance||0;return{name:"tunnel",scope:function(){return e.scope},server:function(n){return t=n,function(){}},client:function(e,t){var r=u(e);i("tunnel:connect - connect to portal:"+r.portal),n.gossip.connect(r.portal,function(e,o){e?(i("tunnel:connect - failed connect to portal:"+r.portal+" "+e.message),t(e)):(i("tunnel:connect - portal connected, tunnel to target:"+r.target),t(null,o.tunnel.connect({target:r.target,instance:r.instance,origin:n.id},noop)))})},parse:u,stringify:function(){if(r)return["tunnel",r,n.id,o].join(":")}}}});var c=null;return{setupIsConnectionOkHandler:function(n){c=n},announce:function(e){i("tunnel:portal - received endpoint announcement from:"+this.id),r[this.id]=n.peers[this.id][0]},connect:function(e){if(!e)return ErrorDuplex("opts *must* be provided");if(r[e.target])return i("tunnel:portal - received tunnel request for target:"+e.target+", from:"+this.id),r[e.target].tunnel.connect(e,noop);if(e.target===n.id){function o(){var n=DuplexPair();return n[0].address="tunnel:@"+SSB.remoteAddress.split(":")[3]+":"+e.origin,t(n[0]),n[1]}return c?c(e.origin)?o():ErrorDuplex("not allowed to connect"):o()}return ErrorDuplex("could not connect to:"+e.target)},ping:function(){return Date.now()}}}; },{"./package.json":596,"pull-pair/duplex":428,"ssb-ref":589}],596:[function(require,module,exports){ module.exports={ @@ -3154,6 +3154,6 @@ exports.manifest={getFeed:"source",getFeedReverse:"source",getTangle:"async",get var Flume=require("flumedb"),OffsetLog=require("flumelog-aligned-offset"),OffsetLogCompat=require("flumelog-aligned-offset/compat"),codec=require("flumecodec/json"),keys=require("ssb-keys"),path=require("path");module.exports=function(e,n,i){console.log("dir:",e),i=i||{};var r=OffsetLogCompat(OffsetLog(path.join(e,"log.offset"),{blockSize:65536,codec:codec})),t=Flume(r,!0,(e,n)=>{if(e&&e.value&&"string"==typeof e.value.content){var i=keys.unbox(e.value.content,SSB.net.config.keys.private);if(!i)return n(null,e);var r=e.value.content;e.value.content=i,e.value.meta={private:!0,original:{content:r}},n(null,e)}else n(null,e)}).use("keys",require("./indexes/keys")()).use("clock",require("./indexes/clock")());t.last=require("./indexes/last")(),t.del=((e,n)=>{t.keys.get(e,(e,i,t)=>e?n(e):null==t?n(new Error("seq is null!")):void r.del(t,n))}),t._flumeUse=function(e,n){return t.use(e,n),t[e]},t.id=n;var u=require("ssb-backlinks");t.backlinks=u.init(t);var s=require("ssb-friends");t.friends=s.init(t,i),require("ssb-peer-invites").init(t,i);var l=require("ssb-query");return t.query=l.init(t),t.getStatus=function(){var e={},n=!0;for(var i in t)t[i]&&"object"==typeof t[i]&&"function"==typeof t[i].since&&(e[i]=t[i].since.value,n=n&&e[i]===t.since.value);return{since:t.since.value,plugins:e,sync:n}},t.add=function(e,n,i){var r={key:e,value:n,timestamp:Date.now()};t.append(r,function(e){e?i(e):i(null,r)})},t}; },{"./indexes/clock":5,"./indexes/keys":6,"./indexes/last":7,"flumecodec/json":176,"flumedb":177,"flumelog-aligned-offset":182,"flumelog-aligned-offset/compat":180,"path":344,"ssb-backlinks":553,"ssb-friends":571,"ssb-keys":573,"ssb-peer-invites":581,"ssb-query":587}],651:[function(require,module,exports){ -const Notify=require("pull-notify");exports.manifest={message:"async"},exports.permissions={anonymous:{allow:["message"]}},exports.name="tunnelMessage",exports.init=function(e,n){var t=Notify(),s=[];return e.on("rpc:connect",function(e,n){n||s.push(e)}),{acceptMessages:function(e){SSB.net.tunnel.setupIsConnectionOkHandler(n=>{const s=e(n);return s&&t({type:"info",user:n,data:"connected"}),s}),SSB.net.connect(SSB.remoteAddress,(e,n)=>{if(e)throw e;n.tunnel.announce()})},connect:function(e){const n=e.substring(1,e.indexOf(".")),o="tunnel:@"+SSB.remoteAddress.split(":")[3]+":"+e+"~shs:"+n;t({type:"info",user:e,data:"waiting for accept"}),SSB.net.connect(o,(e,n)=>{if(e)throw e;s.push(n),t({type:"info",user:n.id,data:"connected"})})},sendMessage:function(e,n){var o=[];s.forEach(s=>{try{s.tunnelMessage.message({type:e,message:n})}catch(e){t({type:"info",user:s.id,data:"disconnected"}),o.push(s)}}),s=s.filter(e=>!o.includes(e)),t({type:e,user:SSB.net.id,data:n})},message:function(e){t({type:e.type,user:this.id,data:e.message})},messages:function(){return t.listen()}}}; +const Notify=require("pull-notify");exports.manifest={message:"async"},exports.permissions={anonymous:{allow:["message"]}},exports.name="tunnelMessage",exports.init=function(e,n){var t=Notify(),s=[],i="";return e.on("rpc:connect",function(e,n){n||e.id!=i||(i="",s.push(e),e.on("closed",n=>{s=s.filter(n=>n.id!=e.id),t({type:"info",user:e.id,data:"disconnected"})}))}),{acceptMessages:function(e){SSB.net.tunnel.setupIsConnectionOkHandler(n=>{const s=e(n);return s&&(t({type:"info",user:n,data:"connected"}),i=n),s}),SSB.net.connect(SSB.remoteAddress,(e,n)=>{if(e)throw e;n.tunnel.announce()})},connect:function(e,n){const i=e.substring(1,e.indexOf(".")),o="tunnel:@"+SSB.remoteAddress.split(":")[3]+":"+e+"~shs:"+i;t({type:"info",user:e,data:"waiting for accept"}),SSB.net.connect(o,(e,i)=>{if(e)return n(e);s.push(i),t({type:"info",user:i.id,data:"connected"}),i.on("closed",e=>{s=s.filter(e=>e.id!=i.id),t({type:"info",user:i.id,data:"disconnected"})}),n&&n()})},disconnect:function(){s.forEach(e=>{try{e.close(!0)}catch(e){}t({type:"info",user:e.id,data:"disconnected"})}),s=[]},sendMessage:function(e,n){var i=[];s.forEach(s=>{try{s.tunnelMessage.message({type:e,message:n})}catch(e){t({type:"info",user:s.id,data:"disconnected"}),i.push(s)}}),i.length>0&&(s=s.filter(e=>!i.includes(e))),t({type:e,user:SSB.net.id,data:n})},message:function(e){t({type:e.type,user:this.id,data:e.message})},messages:function(){return t.listen()}}}; },{"pull-notify":427}]},{},[1]); diff --git a/package.json b/package.json index 7456cfc..bf634d8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ssb-browser-core", "description": "", - "version": "3.0.0", + "version": "3.1.0", "homepage": "https://github.com/arj03/ssb-browser-core", "repository": { "type": "git",