<commit_before>'use strict'

const debug = require('debug')
const log = debug('libp2p:tcp')
const tcp = require('net')
const multiaddr = require('multiaddr')
const Address6 = require('ip-address').Address6
const mafmt = require('mafmt')
// const parallel = require('run-parallel')
const contains = require('lodash.contains')
const os = require('os')
const Connection = require('interface-connection').Connection

exports = module.exports = TCP

const IPFS_CODE = 421
const CLOSE_TIMEOUT = 2000

function TCP () {
  if (!(this instanceof TCP)) {
    return new TCP()
  }

  this.dial = function (ma, options, callback) {
    if (typeof options === 'function') {
      callback = options
      options = {}
    }

    if (!callback) {
      callback = function noop () {}
    }

    const socket = tcp.connect(ma.toOptions())
    const conn = new Connection(socket)

    socket.on('timeout', () => {
      conn.emit('timeout')
    })

    socket.on('connect', () => {
      callback(null, conn)
      conn.emit('connect')
    })

    conn.getObservedAddrs = (cb) => {
      return cb(null, [ma])<commit_msg>pass the err on the callback too<commit_after>'use strict'

const debug = require('debug')
const log = debug('libp2p:tcp')
const tcp = require('net')
const multiaddr = require('multiaddr')
const Address6 = require('ip-address').Address6
const mafmt = require('mafmt')
// const parallel = require('run-parallel')
const contains = require('lodash.contains')
const os = require('os')
const Connection = require('interface-connection').Connection

exports = module.exports = TCP

const IPFS_CODE = 421
const CLOSE_TIMEOUT = 2000

function TCP () {
  if (!(this instanceof TCP)) {
    return new TCP()
  }

  this.dial = function (ma, options, callback) {
    if (typeof options === 'function') {
      callback = options
      options = {}
    }

    if (!callback) {
      callback = function noop () {}
    }

    const socket = tcp.connect(ma.toOptions())
    const conn = new Connection(socket)

    socket.on('timeout', () => {
      conn.emit('timeout')
    })

    socket.once('error', (err) => {
      callback(err)
    })

    socket.on('connect', () => {
      callback(null, conn)
      conn.emit('connect')
    })

    conn.getObservedAddrs = (cb) => {
      return cb(null, [ma])
{'fraction_non_alphanumeric': 0.15438290449193195, 'fraction_numerical': 0.00872219799389446, 'mean_word_length': 3.303939962476548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '2792062', 'n_tokens_mistral': 712, 'n_tokens_neox': 682, 'n_words': 178}