aboutsummaryrefslogtreecommitdiffstats
path: root/handshake
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-04-18 18:04:45 -0400
committerSam Anthony <sam@samanthony.xyz>2025-04-18 18:04:45 -0400
commitbfaad07bab58207d802ea1d94539a29ff6c97fce (patch)
treefddb7f99910b8d3a55c06d535e16e81368f21e7c /handshake
parent67b550d22eb8cd312d282898d0d22bbe368d6d7a (diff)
downloadhose-bfaad07bab58207d802ea1d94539a29ff6c97fce.zip
acceptConnection()
Diffstat (limited to 'handshake')
-rw-r--r--handshake/handshake.go2
-rw-r--r--handshake/receive.go14
-rw-r--r--handshake/send.go2
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 {