mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2024-12-04 18:00:18 +00:00
Successful connection
This commit is contained in:
parent
8007b06e4b
commit
3959d9466a
@ -2,32 +2,6 @@ import { websocket_transport } from './snippets/libp2p-wasm-ext-0a95fd7509554c17
|
||||
|
||||
let wasm;
|
||||
|
||||
const heap = new Array(32).fill(undefined);
|
||||
|
||||
heap.push(undefined, null, true, false);
|
||||
|
||||
function getObject(idx) { return heap[idx]; }
|
||||
|
||||
let heap_next = heap.length;
|
||||
|
||||
function dropObject(idx) {
|
||||
if (idx < 36) return;
|
||||
heap[idx] = heap_next;
|
||||
heap_next = idx;
|
||||
}
|
||||
|
||||
function takeObject(idx) {
|
||||
const ret = getObject(idx);
|
||||
dropObject(idx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
function _assertBoolean(n) {
|
||||
if (typeof(n) !== 'boolean') {
|
||||
throw new Error('expected a boolean argument');
|
||||
}
|
||||
}
|
||||
|
||||
const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
|
||||
cachedTextDecoder.decode();
|
||||
@ -45,6 +19,12 @@ function getStringFromWasm0(ptr, len) {
|
||||
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
const heap = new Array(32).fill(undefined);
|
||||
|
||||
heap.push(undefined, null, true, false);
|
||||
|
||||
let heap_next = heap.length;
|
||||
|
||||
function addHeapObject(obj) {
|
||||
if (heap_next === heap.length) heap.push(heap.length + 1);
|
||||
const idx = heap_next;
|
||||
@ -56,6 +36,26 @@ function addHeapObject(obj) {
|
||||
return idx;
|
||||
}
|
||||
|
||||
function getObject(idx) { return heap[idx]; }
|
||||
|
||||
function dropObject(idx) {
|
||||
if (idx < 36) return;
|
||||
heap[idx] = heap_next;
|
||||
heap_next = idx;
|
||||
}
|
||||
|
||||
function takeObject(idx) {
|
||||
const ret = getObject(idx);
|
||||
dropObject(idx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
function _assertBoolean(n) {
|
||||
if (typeof(n) !== 'boolean') {
|
||||
throw new Error('expected a boolean argument');
|
||||
}
|
||||
}
|
||||
|
||||
let WASM_VECTOR_LEN = 0;
|
||||
|
||||
const cachedTextEncoder = new TextEncoder('utf-8');
|
||||
@ -320,6 +320,10 @@ async function load(module, imports) {
|
||||
function getImports() {
|
||||
const imports = {};
|
||||
imports.wbg = {};
|
||||
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
||||
const ret = getStringFromWasm0(arg0, arg1);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbg_error_09919627ac0992f5 = function() { return logError(function (arg0, arg1) {
|
||||
try {
|
||||
console.error(getStringFromWasm0(arg0, arg1));
|
||||
@ -346,10 +350,6 @@ function getImports() {
|
||||
_assertBoolean(ret);
|
||||
return ret;
|
||||
};
|
||||
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
||||
const ret = getStringFromWasm0(arg0, arg1);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
||||
const obj = getObject(arg1);
|
||||
const ret = typeof(obj) === 'string' ? obj : undefined;
|
||||
@ -443,6 +443,13 @@ function getImports() {
|
||||
return ret;
|
||||
}, arguments) };
|
||||
imports.wbg.__wbg_clearTimeout_65417660fe82f08d = typeof clearTimeout == 'function' ? clearTimeout : notDefined('clearTimeout');
|
||||
imports.wbg.__wbg_now_c2563c77371d3ec4 = function() { return logError(function (arg0) {
|
||||
const ret = getObject(arg0).now();
|
||||
return ret;
|
||||
}, arguments) };
|
||||
imports.wbg.__wbg_debug_8d5c9682707743f7 = function() { return logError(function (arg0) {
|
||||
console.debug(getObject(arg0));
|
||||
}, arguments) };
|
||||
imports.wbg.__wbg_self_86b4b13392c7af56 = function() { return handleError(function () {
|
||||
const ret = self.self;
|
||||
return addHeapObject(ret);
|
||||
@ -614,6 +621,10 @@ function getImports() {
|
||||
imports.wbg.__wbg_set_1a930cfcda1a8067 = function() { return logError(function (arg0, arg1, arg2) {
|
||||
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
|
||||
}, arguments) };
|
||||
imports.wbg.__wbg_get_72332cd2bc57924c = function() { return handleError(function (arg0, arg1) {
|
||||
const ret = Reflect.get(getObject(arg0), getObject(arg1));
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
imports.wbg.__wbg_buffer_34f5ec9f8a838ba0 = function() { return logError(function (arg0) {
|
||||
const ret = getObject(arg0).buffer;
|
||||
return addHeapObject(ret);
|
||||
@ -635,12 +646,12 @@ function getImports() {
|
||||
const ret = wasm.memory;
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
imports.wbg.__wbindgen_closure_wrapper6843 = function() { return logError(function (arg0, arg1, arg2) {
|
||||
const ret = makeMutClosure(arg0, arg1, 436, __wbg_adapter_28);
|
||||
imports.wbg.__wbindgen_closure_wrapper12207 = function() { return logError(function (arg0, arg1, arg2) {
|
||||
const ret = makeMutClosure(arg0, arg1, 649, __wbg_adapter_28);
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
imports.wbg.__wbindgen_closure_wrapper13284 = function() { return logError(function (arg0, arg1, arg2) {
|
||||
const ret = makeMutClosure(arg0, arg1, 727, __wbg_adapter_31);
|
||||
imports.wbg.__wbindgen_closure_wrapper19008 = function() { return logError(function (arg0, arg1, arg2) {
|
||||
const ret = makeMutClosure(arg0, arg1, 947, __wbg_adapter_31);
|
||||
return addHeapObject(ret);
|
||||
}, arguments) };
|
||||
|
||||
|
@ -19,6 +19,7 @@ use libp2p::yamux::YamuxConfig;
|
||||
use libp2p::{identity, noise, Multiaddr, NetworkBehaviour, PeerId, Swarm, Transport};
|
||||
use libp2p::swarm::SwarmEvent;
|
||||
use wasm_bindgen::throw_str;
|
||||
use wasm_rs_dbg::dbg;
|
||||
|
||||
pub const PROTOCOL_NAME: &'static str = "/fluence/particle/2.0.0";
|
||||
|
||||
@ -46,16 +47,19 @@ pub fn test() {
|
||||
|
||||
Swarm::new(transport, behaviour, local_peer_id)
|
||||
};
|
||||
let event = swarm.select_next_some();
|
||||
|
||||
let addr = Multiaddr::from_str("/dns4/kras-00.fluence.dev/tcp/19990/wss/p2p/12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e")
|
||||
.unwrap_or_else(|_| panic!("failed to parse multiaddr"));
|
||||
swarm.dial(addr).unwrap_or_else(|_| panic!("failed to dial"));
|
||||
wasm_rs_dbg::dbg!("dial succeed");
|
||||
dbg!("dial succeed");
|
||||
loop {
|
||||
select! {
|
||||
event = swarm.select_next_some() => {
|
||||
if let SwarmEvent::NewListenAddr { address, .. } = event {
|
||||
println!("Listening on {:?}", address);
|
||||
dbg!("Listening on {:?}", address);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ docker run --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence
|
||||
*/
|
||||
export const nodes = [
|
||||
{
|
||||
multiaddr: '/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
peerId: '12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
multiaddr: '/dns4/kras-00.fluence.dev/tcp/19990/wss/p2p/12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e',
|
||||
peerId: '12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e',
|
||||
},
|
||||
];
|
||||
|
@ -128,7 +128,16 @@ describe('Typescript usage suite', () => {
|
||||
it('check connection should work', async function () {
|
||||
await peer.start({ connectTo: nodes[0] });
|
||||
|
||||
function delay(t: any) {
|
||||
return new Promise(function(resolve) {
|
||||
setTimeout(function() {
|
||||
resolve(0);
|
||||
}, t);
|
||||
});
|
||||
}
|
||||
|
||||
const isConnected = await checkConnection(peer);
|
||||
await delay(5000);
|
||||
|
||||
expect(isConnected).toEqual(true);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user