afl-transmit/net/peer.go
2020-06-19 15:31:20 +02:00

31 lines
548 B
Go

package net
import (
"log"
"net"
)
type Peer struct {
Address string
}
// Sends the given content to the peer
func (p *Peer) SendToPeer(content []byte) {
// Build up a connection
tcpConn, dialErr := net.Dial("tcp", p.Address)
if dialErr != nil {
log.Printf("Unable to connect to peer %s: %s", p.Address, dialErr)
return
}
// Send
_, writeErr := tcpConn.Write(content)
if writeErr != nil {
log.Printf("Unable to write to peer %s: %s", tcpConn.RemoteAddr().String(), writeErr)
return
}
// Close connection
tcpConn.Close()
}