package net.yeputons.spbau.spring2016.torrent;

import net.yeputons.spbau.spring2016.torrent.protocol.Request;

import java.io.IOException;
import java.net.Socket;
import java.net.SocketAddress;

public class TorrentConnection extends SocketDataStreamsWrapper {
    public TorrentConnection(Socket socket) throws IOException {
        super(socket);
    }

    public static TorrentConnection connect(SocketAddress address) throws IOException {
        Socket socket = new Socket();
        try {
            socket.connect(address);
        } catch (IOException e) {
            try {
                socket.close();
            } catch (IOException e1) {
                e.addSuppressed(e1);
            }
            throw e;
        }
        return new TorrentConnection(socket);
    }

    public synchronized <T> T makeRequest(Request<T> r) throws IOException {
        return r.makeRequest(getInputStream(), getOutputStream());
    }
}

@@ -103,16 +103,73 @@
 Request;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -312,16 +312,104 @@
 apper %7B%0A
+    private static final Logger LOG = LoggerFactory.getLogger(TorrentConnection.class);%0A
     publ
@@ -575,32 +575,80 @@
 s IOException %7B%0A
+        LOG.debug(%22Connecting to %7B%7D%22, address);%0A
         Socket s
@@ -915,16 +915,16 @@
 hrow e;%0A
-
         
@@ -917,32 +917,133 @@
 ow e;%0A        %7D%0A
+        LOG.debug(%22Connected to %7B%7D, local endpoint is %7B%7D%22, address, socket.getLocalSocketAddress());%0A
         return n

add logging in .connect()