<commit_before>var os=require('os');
var fs = require('fs');
var ifaces=os.networkInterfaces();
var exec = require('child_process').exec;
var superagent = require('superagent');
var request = require('request');

// This function extremely fragile!
exports.get_public_ip = function() {
  for (var dev in ifaces) {
    var addr_object_arr =  ifaces[dev].filter(function(addr_obj){
      return addr_obj.family === 'IPv4' && addr_obj.address != '127.0.0.1'
    });

    if (addr_object_arr.length === 0)
      continue;

    var addr = addr_object_arr[0].address;
    return addr;
  }
}


function notify_server_when_transfer_succeeded(orig_cmd) {
  superagent.post(server_addr + ':' + cmd_port)
    .send(
      {'cmd': 'transfer_succeeded',
       'from' : orig_cmd.from,
       'to' : orig_cmd.to
      })
    .end(function(error, res){
      if (error) {
	console.error('Notify server transfer succeeded error!' + error);
	return ;
      }
    });
}

function notify_server_when_transfer_failed(orig_cmd) {
  superagent.post(server_addr + ':' + cmd_port)
    .send(
      {'cmd': 'transfer_failed',
       'from' : orig_cmd.from,
       'to' : orig_cmd.to
      })
    .end(function(error, res){
      if (error) {
	console.error('Notify server transfer failed error!' + error);
	return ;
      }
    });
}


exports.transfer = function(cmd) {
  var readStream = fs.createReadStream(cmd.from_path);
  readStream.pipe(request.post('http://' + cmd.to + ':' + file_port));
  
  readStream
    .on('close', function() {
      notify_server_when_transfer_succeeded(cmd);
    })
    .on('error', function(error) {
      console.error('read error: ' + error);
      notify_server_when_transfer_failed(cmd);
    });
}<commit_msg>Revert "01567b"<commit_after>var os=require('os');
var fs = require('fs');
var ifaces=os.networkInterfaces();
var exec = require('child_process').exec;
var superagent = require('superagent');
var request = require('request');

// This function extremely fragile!
exports.get_public_ip = function() {
  for (var dev in ifaces) {
    var addr_object_arr =  ifaces[dev].filter(function(addr_obj){
      return addr_obj.family === 'IPv4' && addr_obj.address != '127.0.0.1'
    });

    if (addr_object_arr.length === 0)
      continue;

    var addr = addr_object_arr[0].address;
    return addr;
  }
}


function notify_server_when_transfer_succeeded(orig_cmd) {
  superagent.post(server_addr + ':' + cmd_port)
    .send(
      {'cmd': 'transfer_succeeded',
       'from' : orig_cmd.from,
       'to' : orig_cmd.to
      })
    .end(function(error, res){
      if (error) {
	console.error('Notify server transfer succeeded error!' + error);
	return ;
      }
    });
}

function notify_server_when_transfer_failed(orig_cmd) {
  superagent.post(server_addr + ':' + cmd_port)
    .send(
      {'cmd': 'transfer_failed',
       'from' : orig_cmd.from,
       'to' : orig_cmd.to
      })
    .end(function(error, res){
      if (error) {
	console.error('Notify server transfer failed error!' + error);
	return ;
      }
    });
}


exports.transfer = function(cmd) {
  var readStream = fs.createReadStream(cmd.from_path);
  readStream.pipe(request.post('http://' + cmd.to + ':' + file_port));
  
  readStream
    .on('end', function() {
      notify_server_when_transfer_succeeded(cmd);
    })
    .on('error', function(error) {
      console.error('read error: ' + error);
      notify_server_when_transfer_failed(cmd);
    });
}
{'fraction_non_alphanumeric': 0.15496227510156704, 'fraction_numerical': 0.006674405107370864, 'mean_word_length': 3.3632911392405065, 'pattern_counts': {'":': 0, '<': 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': '2038165', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1152, 'n_words': 213}