diff options
Diffstat (limited to 'handshake')
| -rw-r--r-- | handshake/handshake.go | 2 | ||||
| -rw-r--r-- | handshake/receive.go | 14 | ||||
| -rw-r--r-- | handshake/send.go | 2 |
3 files changed, 4 insertions, 14 deletions
diff --git a/handshake/handshake.go b/handshake/handshake.go index e5e3c37..d4d1ab4 100644 --- a/handshake/handshake.go +++ b/handshake/handshake.go @@ -9,7 +9,7 @@ import ( ) const ( - port = "60322" + port = 60322 network = "tcp" timeout = 1 * time.Minute diff --git a/handshake/receive.go b/handshake/receive.go index 986b967..b2a0aa7 100644 --- a/handshake/receive.go +++ b/handshake/receive.go @@ -12,6 +12,7 @@ import ( "git.samanthony.xyz/hose/hosts" "git.samanthony.xyz/hose/key" + hose_net "git.samanthony.xyz/hose/net" "git.samanthony.xyz/hose/util" ) @@ -27,7 +28,7 @@ var errVerifyKey = errors.New("host key verification failed") // receive receives the public keys of a remote host. // The user is asked to verify the keys before they are saved to the known hosts file. func receive(rhost string) error { - conn, err := acceptConnection() + conn, err := hose_net.AcceptConnection(network, port) if err != nil { return err } @@ -56,17 +57,6 @@ func receive(rhost string) error { return hosts.Add(hosts.Host{raddr, rBoxPubKey, rSigPubKey}) } -func acceptConnection() (net.Conn, error) { - laddr := net.JoinHostPort("", port) - ln, err := net.Listen(network, laddr) - if err != nil { - return nil, err - } - defer ln.Close() - util.Logf("listening on %s", laddr) - return ln.Accept() -} - func receiveKeys(conn net.Conn) (key.BoxPublicKey, key.SigPublicKey, error) { // Receive public box (encryption) key from remote host. var rBoxPubKey key.BoxPublicKey diff --git a/handshake/send.go b/handshake/send.go index 444db70..95c8f48 100644 --- a/handshake/send.go +++ b/handshake/send.go @@ -31,7 +31,7 @@ func loadKeys() (key.BoxPublicKey, key.SigPublicKey, error) { } func sendKeys(rhost string, boxPubKey key.BoxPublicKey, sigPubKey key.SigPublicKey) error { - raddr := net.JoinHostPort(rhost, port) + raddr := net.JoinHostPort(rhost, fmt.Sprintf("%d", port)) util.Logf("connecting to %s...", raddr) conn, err := dialWithTimeout(network, raddr, timeout) if err != nil { |