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

A new bittorent extension (like ut_pex, ut_metadata) to send plain chat message to peer #368

Closed
vairabagni opened this issue Jul 6, 2015 · 6 comments
Labels

Comments

@vairabagni
Copy link

@vairabagni vairabagni commented Jul 6, 2015

How can I use this extension or ut_metadata or by creating a new one to be able to send messages to other peer (chat message) ?

I just started by creating a new extension which i am thinking of integrating that into webtorrent. So I modified torrent.js (inside webtorrent, ln 463) - _onWire callback - this block is same as that of ut_pex.

if (typeof ut_message === 'function') {
    wire.use(ut_message())

    //wire.ut_message.start() // TODO two-way communication
    wire.ut_message.on('peer', function (peer) {
      debug('ut_message: got peer: %s (from %s)', peer, addr)
      self.addPeer(peer)
    })

    wire.ut_message.on('dropped', function (peer) {
      // the remote peer believes a given peer has been dropped from the swarm.
      // if we're not currently connected to it, then remove it from the swarm's queue.
      debug('ut_message: dropped peer: %s (from %s)', peer, addr)
      var peerObj = self.swarm._peers[peer]
      if (!peerObj || !peerObj.conn) self.swarm.removePeer(peer)
    })
  }

Is it required? Or i can just use any extension (ut_metadata, ut_pex or mine - ut_message) as:

torrent.swarm.on("wire", function(wire) {
    console.log("onwire - " + wire.peerId + " - " + wire.remoteAddress + ':' + wire.remotePort);

    wire.on('extended', function (ext, obj) {
        console.log('extended', ext, obj.toString());
    });
    wire.use(ut_message()); 
        //or
        wire.use(ut_metadata());
        //or
    wire.use(ut_pex()); 

    wire.extended(3, 'hello'); //first param will be either 1, 2 or 3
});
@madd512

This comment has been minimized.

Copy link

@madd512 madd512 commented Jul 6, 2015

@vairabagni

This comment has been minimized.

Copy link
Author

@vairabagni vairabagni commented Jul 6, 2015

My Seeder looks like:

var client = new WebTorrent({
    dht: {
        announce: ['http://127.0.0.1:6881/announce']
    }
});

client.seed('something.mp4', {
  announce: ['http://127.0.0.1:6881/announce'],
  private: false
}, function onTorrent (torrent) {
        // Client is seeding the file!
    console.log('MargnetURI:', torrent.magnetURI);
    console.log('Info hash:', torrent.infoHash);
});

client.on('torrent', function (torrent) {
       torrent.on("wire", function(wire) {
        console.log("onwire - " + wire.peerId + " - " + wire.remoteAddress + ':' + wire.remotePort);

        wire.on('extended', function (ext, obj) {
            console.log('extended', ext, obj.toString());
        });

        wire.ut_pex.on('warning', function (err) {
            console.log('warning', err.message)
        })

        wire.extended(2, 'hello');
    });
});

-- The callback onwire will be called if i specify

torrent.swarm.on("wire", function(wire) {

instead of

torrent.on("wire", function(wire) {

Which one I should use ?

-- When i restart the local tracker then the litcher is getting the message 'hello'. Is there anything wrong I am doing?

@madd512

This comment has been minimized.

Copy link

@madd512 madd512 commented Jul 6, 2015

If I were you, I'd get started using the test.

https://github.com/feross/webtorrent/blob/master/test/extensions.js

Provided your extension is properly named, you can then send messages like this:

wire.extended('my_extension', 'ayyyy lmao')
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 6, 2015

What @devtristan said – thanks for helping out!

@vairabagni

This comment has been minimized.

Copy link
Author

@vairabagni vairabagni commented Jul 8, 2015

I was using webtorrent@0.49.2, that may be the reason why "torrent.on("wire", function(wire) {" was not triggering. When i updated to webtorrent@0.51.1 it starts working.

Yes, @devtristan I have created a new extension for message communication and I will be using the way you suggested.

Thanks both you.

@fultonm

This comment has been minimized.

Copy link

@fultonm fultonm commented Jan 4, 2017

How is your extension working @vairabagni? You can add extensions to the list of known extensions by making a pull request here https://github.com/feross/bittorrent-protocol#extension-api

I'm interested in something like this 👍

@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 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
4 participants
You can’t perform that action at this time.