<commit_before>import telehash from "telehash"
import http from "http"
import Server from "server/router.js"

var teletunnel = function teletunnel(proxy, {hostname, port, subdomain, mesh}, cb){

  proxy = (typeof proxy === "number") ? "http://127.0.0.1:" + proxy
        : (typeof proxy === "object") ? proxy
        : null;

  if (!proxy) throw new Error("invalid local argument")

  function onMesh(err, mesh){
    console.log("onmesh")
    if (err) throw err;

    function onRemote(res){
      res.on("data",function(data){
        var server = mesh.link(JSON.parse(data.toString()));

        server.status(function(err,status){
          console.log("server link up: ", status.up)

          mesh.proxy(proxy);

        })
      })
    }

    var url = "http://" + hostname + ":" + port +  "/telehash.hashname"
    console.log("url", url)
    http.request( url , onRemote)
        .on("error", cb)
        .end()

  }

  if (!mesh)
    telehash.load({id: process.cwd() + "/.teletunnel_local_id"}, onMesh);<commit_msg>add callback with url of remote tunnel<commit_after>import telehash from "telehash"
import http from "http"
import Server from "./server/server.js"

var teletunnel = function teletunnel(proxy, {hostname, port, subdomain, mesh}, cb){

  proxy = (typeof proxy === "number") ? "http://127.0.0.1:" + proxy
        : (typeof proxy === "object") ? proxy
        : null;

  if (!proxy) throw new Error("invalid local argument")

  function onMesh(err, mesh){
    console.log("onmesh")
    if (err) throw err;

    function onRemote(res){
      res.on("data",function(data){
        var server = mesh.link(JSON.parse(data.toString()));

        server.status(function(err,status){
          console.log("server link up: ", status.up)
          var url = "http://" + mesh.hashname.substr(0,8) + "." + hostname + ":" + port

          mesh.proxy(proxy);
          cb(null, url);

        })
      })
    }

    var url = "http://" + hostname + ":" + port +  "/telehash.hashname"
    console.log("url", url)
    http.request( url , onRemote)
        .on("error", cb)
        .end()

  }

  if (!mesh)
    telehash.load({id: process.cwd() + "/.teletunnel_local_id"}, onMesh);
{'fraction_non_alphanumeric': 0.17017383348581885, 'fraction_numerical': 0.006404391582799634, 'mean_word_length': 2.6942567567567566, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2168725', 'n_tokens_mistral': 717, 'n_tokens_neox': 693, 'n_words': 171}