diff --git a/daemon/3client.go b/daemon/3client.go new file mode 100644 index 0000000..830fc59 --- /dev/null +++ b/daemon/3client.go @@ -0,0 +1,26 @@ +package daemon + +import ( + "log" + "net/rpc" +) + +// Call connects to the RPC server and requests the passphrase. +func Call() string { + // connect to the UNIX domain socket/Windows named pipe + conn := getConn() + defer conn.Close() + + // create an RPC client using the connection + client := rpc.NewClient(conn) + defer client.Close() + + // request the passphrase from the RPC server + var reply string + if err := client.Call("RCWService.GetPass", "hi", &reply); err != nil { + log.Fatalf("Error calling RCWService.GetPass: %v", err) + } + + // return the passphrase + return reply +} diff --git a/daemon/3clientUNIXGeneric.go b/daemon/3clientUNIXGeneric.go index e7b46f6..a7eb3e2 100644 --- a/daemon/3clientUNIXGeneric.go +++ b/daemon/3clientUNIXGeneric.go @@ -5,29 +5,12 @@ package daemon import ( "log" "net" - "net/rpc" ) -// Call connects to the RPC server and requests the passphrase. -func Call() string { - // connect to the UNIX domain socket +func getConn() net.Conn { conn, err := net.Dial("unix", socketPath) if err != nil { log.Fatalf("Dial error: %v", err) } - defer conn.Close() - - // create an RPC client using the connection - client := rpc.NewClient(conn) - defer client.Close() - - // request the passphrase from the RPC server - var reply string - err = client.Call("RCWService.GetPass", "hi", &reply) - if err != nil { - log.Fatalf("Error calling RCWService.GetPass: %v", err) - } - - // return the passphrase - return reply + return conn } diff --git a/daemon/3clientWindows.go b/daemon/3clientWindows.go index 91c3076..7e38443 100644 --- a/daemon/3clientWindows.go +++ b/daemon/3clientWindows.go @@ -4,31 +4,15 @@ package daemon import ( "log" - "net/rpc" + "net" "github.com/Microsoft/go-winio" ) -// Call connects to the RPC server and requests the passphrase. -func Call() string { - // connect to the Windows named pipe +func getConn() net.Conn { conn, err := winio.DialPipe(socketPath, nil) if err != nil { log.Fatalf("Dial error: %v", err) } - defer conn.Close() - - // create an RPC client using the connection - client := rpc.NewClient(conn) - defer client.Close() - - // request the passphrase from the RPC server - var reply string - err = client.Call("RCWService.GetPass", "hi", &reply) - if err != nil { - log.Fatalf("Error calling RCWService.GetPass: %v", err) - } - - // return the passphrase - return reply + return conn }