diff --git a/app/manage-connection/manage-connection.go b/app/manage-connection/manage-connection.go index d461671ec1a3b4bee8e7db53218bd5c8b7ce8018..0022c4c7a06b8f2b7782af504658429a963a063c 100644 --- a/app/manage-connection/manage-connection.go +++ b/app/manage-connection/manage-connection.go @@ -1 +1,30 @@ package manage_connection + +import ( + "fmt" + "net" +) + +func CreateConnection(destinationAddress string) net.Conn { + fmt.Println("Trying to connect to ", destinationAddress) + // connect to ip with tcp and add the ip of the sender to the connection + conn, err := net.Dial("tcp", destinationAddress) + + if err != nil { + fmt.Println("Error while connecting to the neighbour", err) + } + + return conn +} + +func CreateConnectionWithSpecifiedLocalAddress(senderAddress string, destinationAddress string) net.Conn { + dialer := net.Dialer{LocalAddr: &net.TCPAddr{IP: net.ParseIP(senderAddress)}} + + conn, err := dialer.Dial("tcp", destinationAddress) + + if err != nil { + fmt.Println("Error while connecting to the neighbour", err) + } + + return conn +} \ No newline at end of file