Skip to content

Commit

Permalink
Enhancement: windows now use named pipes for IPC instead of unix sock…
Browse files Browse the repository at this point in the history
…ets to support Windows 10 < 1809
  • Loading branch information
luskaner committed Dec 19, 2024
1 parent f1f2a9a commit c6fb22d
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 24 deletions.
7 changes: 1 addition & 6 deletions launcher-common/ipc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package launcher_common
import (
"github.com/luskaner/ageLANServer/common"
"net"
"os"
"path"
)

const ConfigAdminIpcRevert byte = 0
const ConfigAdminIpcSetup byte = 1
const ConfigAdminIpcExit byte = 2
const configAdminIpcName = common.Name + `-launcher-config-admin-agent`

type (
ConfigAdminIpcSetupCommand struct {
Expand All @@ -23,7 +22,3 @@ type (
Certificate bool
}
)

func ConfigAdminIpcName() string {
return path.Join(os.TempDir(), common.Name+`-launcher-config-admin-agent`)
}
12 changes: 12 additions & 0 deletions launcher-common/ipc_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !windows

package launcher_common

import (
"os"
"path"
)

func ConfigAdminIpcPath() string {
return path.Join(os.TempDir(), configAdminIpcName)
}
5 changes: 5 additions & 0 deletions launcher-common/ipc_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package launcher_common

func ConfigAdminIpcPath() string {
return `\\.\pipe\` + configAdminIpcName
}
19 changes: 2 additions & 17 deletions launcher-config-admin-agent/internal/ipc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
launcherCommon "github.com/luskaner/ageLANServer/launcher-common"
"github.com/luskaner/ageLANServer/launcher-common/executor"
"net"
"os"
)

var mappedCdn = false
Expand Down Expand Up @@ -121,30 +120,16 @@ func handleRevert(decoder *gob.Decoder) int {
}

func RunIpcServer() (errorCode int) {
ipcPath := launcherCommon.ConfigAdminIpcName()

if err := os.Remove(ipcPath); err != nil && !os.IsNotExist(err) {
errorCode = ErrListen
return
}

defer func() {
_ = os.Remove(ipcPath)
}()

l, err := net.Listen("unix", ipcPath)
l, err := SetupIpcServer()
if err != nil {
errorCode = ErrListen
return
}
defer func(l net.Listener) {
_ = l.Close()
RevertIpcServer()
}(l)

if err = os.Chmod(ipcPath, 0666); err != nil {
return
}

var conn net.Conn
for {
conn, err = l.Accept()
Expand Down
30 changes: 30 additions & 0 deletions launcher-config-admin-agent/internal/ipc_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build !windows

package internal

import (
launcherCommon "github.com/luskaner/ageLANServer/launcher-common"
"net"
"os"
)

func SetupIpcServer() (listener net.Listener, err error) {
ipcPath := launcherCommon.ConfigAdminIpcPath()

if err = os.Remove(ipcPath); err != nil && !os.IsNotExist(err) {
return
}

listener, err = net.Listen("unix", ipcPath)

if err != nil {
return
}

err = os.Chmod(ipcPath, 0666)
return
}

func RevertIpcServer() {
_ = os.Remove(launcherCommon.ConfigAdminIpcPath())
}
26 changes: 26 additions & 0 deletions launcher-config-admin-agent/internal/ipc_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package internal

import (
"fmt"
"github.com/Microsoft/go-winio"
launcherCommon "github.com/luskaner/ageLANServer/launcher-common"
"net"
"os/user"
)

func SetupIpcServer() (listener net.Listener, err error) {
var u *user.User
u, err = user.Current()
if err != nil {
return nil, err
}
pc := &winio.PipeConfig{
InputBufferSize: 1_024,
OutputBufferSize: 1,
SecurityDescriptor: fmt.Sprintf("D:P(A;;GA;;;%s)", u.Uid),
MessageMode: true,
}
return winio.ListenPipe(launcherCommon.ConfigAdminIpcPath(), pc)
}

func RevertIpcServer() {}
1 change: 1 addition & 0 deletions launcher-config/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/luskaner/ageLANServer/launcher-config
go 1.23.0

require (
github.com/Microsoft/go-winio v0.6.2
github.com/deckarep/golang-set/v2 v2.7.0
github.com/luskaner/ageLANServer/common v0.0.0-20241111160911-2abef906e211
github.com/luskaner/ageLANServer/launcher-common v0.0.0-20241111163256-bdcc7ac24582
Expand Down
2 changes: 2 additions & 0 deletions launcher-config/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/andygrunwald/vdf v1.1.0 h1:gmstp0R7DOepIZvWoSJY97ix7QOrsxpGPU6KusKXqvw=
github.com/andygrunwald/vdf v1.1.0/go.mod h1:f31AAs7HOKvs5B167iwLHwKuqKc4bE46Vdt7xQogA0o=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down
2 changes: 1 addition & 1 deletion launcher-config/internal/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func ConnectAgentIfNeeded() (err error) {
return
}
var conn net.Conn
conn, err = net.Dial("unix", launcherCommon.ConfigAdminIpcName())
conn, err = DialIPC()
if err != nil {
return
}
Expand Down
6 changes: 6 additions & 0 deletions launcher-config/internal/admin_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"github.com/luskaner/ageLANServer/common/executor"
"github.com/luskaner/ageLANServer/common/process"
launcherCommon "github.com/luskaner/ageLANServer/launcher-common"
"net"
"time"
)

Expand All @@ -26,3 +28,7 @@ func postAgentStart(file string) {
}
}
}

func DialIPC() (net.Conn, error) {
return net.Dial("unix", launcherCommon.ConfigAdminIpcPath())
}
10 changes: 10 additions & 0 deletions launcher-config/internal/admin_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
package internal

import (
"github.com/Microsoft/go-winio"
launcherCommon "github.com/luskaner/ageLANServer/launcher-common"
"net"
)

func preAgentStart() {}
func postAgentStart(_ string) {}

func DialIPC() (net.Conn, error) {
return winio.DialPipe(launcherCommon.ConfigAdminIpcPath(), nil)
}

0 comments on commit c6fb22d

Please sign in to comment.