public synchronized void connect(Peer p) { DownloadTask dt = new DownloadTask( p, this.torrent.info_hash_as_binary, this.clientID, true, this.getBitField()); dt.addDTListener(this); dt.start(); }
/** * Called when a new peer connects to the client. Check if it is already registered in the peer * list, and if not, create a new DownloadTask for it * * @param s Socket */ public synchronized void connectionAccepted(Socket s) { synchronized (this.task) { String id = s.getInetAddress().getHostAddress() + ":" + s.getPort(); if (!this.task.containsKey(id)) { DownloadTask dt = new DownloadTask( null, this.torrent.info_hash_as_binary, this.clientID, false, this.getBitField(), s); dt.addDTListener(this); this.peerList.put(dt.getPeer().toString(), dt.getPeer()); this.task.put(dt.getPeer().toString(), dt); dt.start(); } } }