<commit_before>'use strict';

var merge = require('merge');
var assert = require('assert');
var Contract = require('../contract');
var Contact = require('./contact');
var AuditStream = require('../audit-tools/audit-stream');
var kad = require('kad');
var Network = require('./');
var inherits = require('util').inherits;
var StorageItem = require('../storage/item');
var async = require('async');
var OfferStream = require('../contract/offer-stream');

/**
 * Creates and a new renter interface
 * @constructor
 * @license AGPL-3.0
 * @extends {Network}
 * @param {Object}  options
 * @param {String} [options.hdKey] - Extended key at 'group index' as per SIP32
 * @param {Number} [options.hdIndex] - Derivation index for hdKey
 * @param {KeyPair}[options.keyPair] - Node's cryptographic identity
 * @param {StorageManager} options.storageManager - Storage manager backend
 * @param {String}  options.bridgeUri - URL for bridge server seed lookup
 * @param {Object}  options.logger - Logger instance
 * @param {Array}   options.seedList - List of seed URIs to join
 * @param {String}  options.rpcAddress - Public node IP or hostname
 * @param {Number}  options.rpcPort - Listening port for RPC
 * @param {Boolean} options.doNotTraverseNat - Skip NAT traversal strategies
 * @param {Number}  options.maxTunnels - Max number of tunnels to provide
 * @param {Number}  options.tunnelServerPort - Port for tunnel server to use
 * @param {Object}  options.tunnelGatewayRange
 * @param {Number}  options.tunnelGatewayRange.min - Min port for gateway bind
 * @param {Number}  options.tunnelGatewayRange.max - Max port for gateway bind
 * @param {Object}  options.rateLimiterOpts - Options for {@link RateLimiter}
 * @param {Object} [options.joinRetry]
 * @param {Number} [options.joinRetry.times] - Times to retry joining net
 * @param {Number} [options.joinRetry.interval] - MS to wait before retrying
 * @emits Network#ready
 * @property {KeyPair} keyPair
 * @property {StorageManager} storageManager
 * @property {kad.Node} node - The underlying DHT node
 * @property {TriggerManager} triggerManager
 * @property {BridgeClient} bridgeClient
 * @property {Contact} contact
 * @property {Transport} transportAdapter
 * @property {kad.Router} router - The underlying DHT router
 * @property {DataChannelServer} dataChannelServer
 */
function RenterInterface(options) {
  if (!(this instanceof RenterInterface)) {
    return new RenterInterface(options);
  }

  Network.call(this, options);
}

inherits(RenterInterface, Network);

/**
 * Publishes a contract directly to a specific contact that will not be
 * relayed to other peers.
 * @param {Contract} contact - The contact to publish the contract
 * @param {Contract} contract - The storage contract to publish
 */
RenterInterface.prototype.publishContract = function(contact, contract) {
  assert(farmer instanceof Contact, 'Invalid contact supplied');
  assert(contract instanceof Contract, 'Invalid contract supplied');

  const data = contract.toObject();
  const topic = contract.getTopicString();
  const nodeID = this.contact.nodeID;
  const id = uuid.v4();

  // This message doesn't need to be relayed as nodes will be selected
  // and communicated with directly, thus the TTL can be set to zero.
  const params = {
    uuid: id,
    topic: topic,
    contents: data,
    publishers: [nodeID],
    ttl: 0,
    contact: this.contact
  }

  // TODO We can use CLAIM command (or similar) here that will also
  // include a transfer token to upload the data to avoid an additional
  // CONSIGNMENT network call for improved effeciency. The CLAIM
  // command can include all the details of a PUBLISH without the TTL
  // topic and publishers.
  var message = new kad.Message({
    method: 'PUBLISH',
    params: params
  });<commit_msg>Let's go ahead and use CLAIM<commit_after>'use strict';

var merge = require('merge');
var assert = require('assert');
var Contract = require('../contract');
var Contact = require('./contact');
var AuditStream = require('../audit-tools/audit-stream');
var kad = require('kad');
var Network = require('./');
var inherits = require('util').inherits;
var StorageItem = require('../storage/item');
var async = require('async');
var OfferStream = require('../contract/offer-stream');

/**
 * Creates and a new renter interface
 * @constructor
 * @license AGPL-3.0
 * @extends {Network}
 * @param {Object}  options
 * @param {String} [options.hdKey] - Extended key at 'group index' as per SIP32
 * @param {Number} [options.hdIndex] - Derivation index for hdKey
 * @param {KeyPair}[options.keyPair] - Node's cryptographic identity
 * @param {StorageManager} options.storageManager - Storage manager backend
 * @param {String}  options.bridgeUri - URL for bridge server seed lookup
 * @param {Object}  options.logger - Logger instance
 * @param {Array}   options.seedList - List of seed URIs to join
 * @param {String}  options.rpcAddress - Public node IP or hostname
 * @param {Number}  options.rpcPort - Listening port for RPC
 * @param {Boolean} options.doNotTraverseNat - Skip NAT traversal strategies
 * @param {Number}  options.maxTunnels - Max number of tunnels to provide
 * @param {Number}  options.tunnelServerPort - Port for tunnel server to use
 * @param {Object}  options.tunnelGatewayRange
 * @param {Number}  options.tunnelGatewayRange.min - Min port for gateway bind
 * @param {Number}  options.tunnelGatewayRange.max - Max port for gateway bind
 * @param {Object}  options.rateLimiterOpts - Options for {@link RateLimiter}
 * @param {Object} [options.joinRetry]
 * @param {Number} [options.joinRetry.times] - Times to retry joining net
 * @param {Number} [options.joinRetry.interval] - MS to wait before retrying
 * @emits Network#ready
 * @property {KeyPair} keyPair
 * @property {StorageManager} storageManager
 * @property {kad.Node} node - The underlying DHT node
 * @property {TriggerManager} triggerManager
 * @property {BridgeClient} bridgeClient
 * @property {Contact} contact
 * @property {Transport} transportAdapter
 * @property {kad.Router} router - The underlying DHT router
 * @property {DataChannelServer} dataChannelServer
 */
function RenterInterface(options) {
  if (!(this instanceof RenterInterface)) {
    return new RenterInterface(options);
  }

  Network.call(this, options);
}

inherits(RenterInterface, Network);

/**
 * Publishes a contract directly to a specific contact and receive a
 * storage offer in the response.
 * @param {Contract} contact - The contact to publish the contract
 * @param {Contract} contract - The storage contract to publish
 */
RenterInterface.prototype.publishContract = function(contact, contract) {
  assert(farmer instanceof Contact, 'Invalid contact supplied');
  assert(contract instanceof Contract, 'Invalid contract supplied');

  const data = contract.toObject();
  const id = uuid.v4();

  const params = {
    uuid: id,
    contents: data,
    contact: this.contact
  }

  var message = new kad.Message({
    method: 'CLAIM',
    params: params
  });
{'fraction_non_alphanumeric': 0.11481956924832407, 'fraction_numerical': 0.0015689630580516332, 'mean_word_length': 4.344512195121951, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '5485273', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1945, 'n_words': 700}