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

tracker timeout in electron app #1116

Closed
BenmasterTM opened this issue Apr 24, 2017 · 4 comments
Closed

tracker timeout in electron app #1116

BenmasterTM opened this issue Apr 24, 2017 · 4 comments

Comments

@BenmasterTM
Copy link

@BenmasterTM BenmasterTM commented Apr 24, 2017

We are using Node.js 7.4.0, Chromium 56.0.2924.87, and Electron 1.6.6.

Im tying to make a simple electron app that read file and share it to webtorrent network (and next step webtorrent-hybrid) but im unable to share any file (or at least is not read by the trackers or something, i try to get the magnet and use in https://instant.io/)

Here is my code:
`const electron = require('electron')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow

const crypto = require('crypto')
const defaultAnnounceList = require('create-torrent').announceList
const path = require('path')
const url = require('url')
const webtorrent = require('webtorrent')
const createTorrent = require('create-torrent')
const parseTorrent = require('parse-torrent')

// Force use of webtorrent trackers on all torrents
/*
global.WEBTORRENT_ANNOUNCE = defaultAnnounceList
.map((arr) => arr[0])
.filter((url) => url.indexOf('wss://') === 0 || url.indexOf('ws://') === 0)
*/

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow

function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600})

// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))

// Open the DevTools.
mainWindow.webContents.openDevTools()

// XXXXXXXXXXXXXXXXX

const PEER_ID = Buffer.from('0.18.0' + crypto.randomBytes(9).toString('base64'))

// Connect to the WebTorrent and BitTorrent networks. WebTorrent Desktop is a hybrid
// client, as explained here: https://webtorrent.io/faq
let client = new webtorrent({ peerId: PEER_ID })
console.log('peerID :' + PEER_ID);


const options = { name: 'MyMovie.mp4'} 
const p = path.join(__dirname, '', 'MyMovie.mp4');
const torrent = client.seed(p, options, function(torrent) {
    //let uri = parseTorrent.toMagnetURI(torrent)
    console.log(torrent.magnetURI);
    
    torrent.on('warning', (err) => torrentWarning(err))
    torrent.on('error', torrentError)
    torrent.on('infoHash', torrentInfoHash)
    torrent.on('metadata', torrentMetadata)
    torrent.on('ready', torrentReady)
    torrent.on('done', torrentDone)
            
});

function torrentWarning(err) {
    console.log("torrent torrentWarning");
    console.log(err)
}
function torrentError() {
    console.log("torrent torrentError");
}
function torrentInfoHash() {
    console.log("torrent torrentInfoHash");
}
function torrentMetadata() {
    console.log("torrent torrentMetadata");
}
function torrentReady() {
    console.log("torrent torrentReady");
}
function torrentDone() {
    console.log("torrent torrentDone");
}

//let uri = parseTorrent.toMagnetURI(torrent)
//console.log(uri);

//var uri = parseTorrent.toMagnetURI(torrent);
//console.log(options);
//console.log(p);
//console.log(uri);

// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.`

When I launch this I get this result:

peerID :0.18.0afJajB8CSLwk
magnet:?xt=urn:btih:6b00ed7f0298ee1ad686e2b90779005d6005ad0b&dn=MyMovie.mp4&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com

and after some seconds I get this:


torrent torrentWarning
Error: tracker request timed out (started) (udp://explodie.org:6969)
    at Timeout.<anonymous> (D:\Escritorio\electro\node_modules\bittorrent-tracker\lib\client\udp-tracker.js:92:18)
    at ontimeout (timers.js:365:14)
    at Timer.unrefdHandle (timers.js:471:5)
torrent torrentWarning
Error: tracker request timed out (started) (udp://tracker.coppersurfer.tk:6969)
    at Timeout.<anonymous> (D:\Escritorio\electro\node_modules\bittorrent-tracker\lib\client\udp-tracker.js:92:18)
    at ontimeout (timers.js:365:14)
    at Timer.unrefdHandle (timers.js:471:5)
torrent torrentWarning
Error: tracker request timed out (started) (udp://tracker.empire-js.us:1337)
    at Timeout.<anonymous> (D:\Escritorio\electro\node_modules\bittorrent-tracker\lib\client\udp-tracker.js:92:18)
    at ontimeout (timers.js:365:14)
    at Timer.unrefdHandle (timers.js:471:5)
torrent torrentWarning
Error: tracker request timed out (started) (udp://tracker.leechers-paradise.org:6969)
    at Timeout.<anonymous> (D:\Escritorio\electro\node_modules\bittorrent-tracker\lib\client\udp-tracker.js:92:18)
    at ontimeout (timers.js:365:14)
    at Timer.unrefdHandle (timers.js:471:5)
torrent torrentWarning
Error: tracker request timed out (started) (udp://tracker.opentrackr.org:1337)
    at Timeout.<anonymous> (D:\Escritorio\electro\node_modules\bittorrent-tracker\lib\client\udp-tracker.js:92:18)
    at ontimeout (timers.js:365:14)
    at Timer.unrefdHandle (timers.js:471:5)

What im doing wrong here? I try to disable windows Firewall and try in linux and get same result, but making ping to explodie.org for example works

@BenmasterTM

This comment has been minimized.

Copy link
Author

@BenmasterTM BenmasterTM commented Apr 27, 2017

More info: Im testing the webtorrent-desktop code, and make my own test, removing all, and i can make webtorrent work in the webtorrent-desktop code, my feelings are, that the webtorrent client need to be created in other window process, because if I follow the webtorrent-desktop system (create webtorrent client in other window, and track events from-to main ipc process) the code to client.seed() work correclty

Can be that? the webtorrent client only work correctly in a separated thread ?

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Apr 27, 2017

If I'm not wrong, The client needs to be in a nodejs (main or a child) process, not inside a window (as it doesn't have TCP/UDP access).

@BenmasterTM

This comment has been minimized.

Copy link
Author

@BenmasterTM BenmasterTM commented May 4, 2017

I found the problem:

let client = new webtorrent({ peerId: PEER_ID })

for some reason the PEER_ID string cause torrent trackers send me a timeout, like the string is not accepted, I remove the peerId in the new webtorrent client, and now works.

What im trying to fix now is, the peers who can connect the webtorrent, I can share torrent with webtorrent clients, but im unable to share the torrents with regular TCP/UDP torrent clients (but i can download new torrents form TCP/UDP clients). I test with webtorrentDesktop and have the same issue, so i think is related directly to webtorrent library.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Apr 19, 2018

Can be that? the webtorrent client only work correctly in a separated thread ?

I believe that Electron renderer processes also have Node.js APIs, so you can use WebTorrent there. We moved it to a separate thread because we didn't want to lock up the UI when WebTorrent uses lots of CPU.

for some reason the PEER_ID string cause torrent trackers send me a timeout, like the string is not accepted, I remove the peerId in the new webtorrent client, and now works.

If the torrent tracker doesn't recognize which torrent client you're using, or that string is invalid somehow, perhaps that was causing problems.

What im trying to fix now is, the peers who can connect the webtorrent, I can share torrent with webtorrent clients, but im unable to share the torrents with regular TCP/UDP torrent clients

That shouldn't happen. If you have more information about that, like a specific torrent file (no copyrighted content, please) which can demonstrate the issue, please open a new issue.

@feross feross closed this Apr 19, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.