Skip to content

Simplify Session lib wrapper #72

@bedeho

Description

@bedeho

Background

The javascript wrapper Session, part of lib, plays a much richer role than the actual libtorrent::session. Among the things it does, is to do internal alert poping, processing, and requesting status updates from torrent and peer plugins. The following excerpt from the constructor is critical to this.

    setInterval(() => {
      // Pop alerts
      var alerts = this.session.popAlerts()

      // Process alerts
      for (var i in alerts) {
        this.process(alerts[i])
      }

      // Request plugin and peer status updates
      for (var [infoHash] of this.torrents.entries()) {
        this.plugin.post_torrent_plugin_status_updates(infoHash)
        this.plugin.post_peer_plugin_status_updates(infoHash)
      }
    }, statusUpdateInterval)

Problem

  • An obvious problem with the above is the significant inflexibility it imposes in how this should be done, from the perspective of a library user.
  • A second problem is that its part of the obstacle in
    making this wrapper layer thinner, and eventually removing it - or at least making it stateless.

Solution

As a halfway house which solves both issues above, and takes us closer to the final goal, would be to remove the internal timer above entirely, and instead add the following functions that the user calls

  • Session.processAlerts()
  • Torrent.postTorrentPluginStatusUpdates(infoHash)
  • Torrent.postPeerPluginStatusUpdates(infoHash)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions