libp2p / js-libp2p-webrtc-star

libp2p WebRTC transport that includes a discovery mechanism provided by the signalling-star
https://libp2p.io
Other
320 stars 96 forks source link

RTC transport channel closed error on transferring large amount of data #262

Open AshishSandey opened 4 years ago

AshishSandey commented 4 years ago

I am trying to transfer files using libp2p webrtc transport using streaming iterables. I am using it-pipe package for this. In the middle of the transfer I get Transport Error: RTC transport channel closed. I suspect that this is happening due to latency as I can recreate this error only on certain devices (mostly low-end smartphones). I am using this generator as asynchronous source for file transfer. async function* fileBufferGenerator(file) { let size = file.size; const bufSize = 2048; for (let i = 0; i < size; i += bufSize) { let fileslice = file.slice(i, Math.min(i + bufSize, size)); let filebuf = await fileslice.arrayBuffer() let bufView = new Uint8Array(filebuf); yield JSON.stringify(Array.from(bufView)) } } This is the code I am using on the sender end let source = await fileBufferGenerator(file); pipe( source, stream ) And this one at the receiver end ` for await (let data of stream.source) {

    let item = JSON.parse(data)
    received += item.length;
    //console.log(data.toString())
    chunks.push(new Uint8Array(item));
    currentProgress = Math.round(received/size*100);

}

` Can anyone please help me with how to do this properly

jacobheun commented 3 years ago

We should look into the size of packets, webrtc can have a bad time if the packets that get sent over the wire are too big (64kb).

It would be good to add tests around trying to choke the transport, we may need to add a chunk limiter here to prevent sending larger packets.