Skip to content

Commit

Permalink
Merge pull request #57 from zjkmxy/master
Browse files Browse the repository at this point in the history
Change Unix socket path
  • Loading branch information
zjkmxy authored Jan 4, 2024
2 parents f36991f + 4051733 commit df57438
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ install -m 644 ./yanfd.toml /usr/local/etc/ndn
rm ./yanfd.toml
```

On MacOS, one also needs to change `socket_path` to `/var/run/nfd.sock` in the copied configuration file.
On MacOS, one also needs to change `socket_path` to `/var/run/nfd/nfd.sock` in the copied configuration file.

### On Windows 10
```text
Expand All @@ -48,7 +48,7 @@ mkdir %APPDATA%\ndn
move yanfd.toml %APPDATA%\ndn\
```

One needs to change `socket_path` to `${TEMP}\\nfd.sock` in the copied configuration file.
One needs to change `socket_path` to `${TEMP}\\nfd\\nfd.sock` in the copied configuration file.
Also, to execute YaNFD on Windows 10, one needs to explicitly specify the configuration path:
```text
yanfd.exe --config=%APPDATA%\ndn\yanfd.toml
Expand Down
2 changes: 1 addition & 1 deletion cmd/yanfdui/templates/config.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<div class="pure-control-group">
<label for="UnixSocketPath">Socket File Path</label>
<input type="text" id="UnixSocketPath" name="UnixSocketPath"
placeholder="${TEMP}\\nfd.sock" value="{{.Setting.UnixSocketPath}}"/>
placeholder="${TEMP}\\nfd\\nfd.sock" value="{{.Setting.UnixSocketPath}}"/>
</div>
</fieldset>
<fieldset>
Expand Down
2 changes: 1 addition & 1 deletion face/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ func Configure() {
udp6MulticastAddress = core.GetConfigStringDefault("faces.udp.multicast_address_ipv6", "ff02::114")
udpLifetime = time.Duration(core.GetConfigUint16Default("faces.udp.lifetime", 600)) * time.Second
tcpLifetime = time.Duration(core.GetConfigUint16Default("faces.tcp.lifetime", 600)) * time.Second
UnixSocketPath = os.ExpandEnv(core.GetConfigStringDefault("faces.unix.socket_path", "/run/nfd.sock"))
UnixSocketPath = os.ExpandEnv(core.GetConfigStringDefault("faces.unix.socket_path", "/run/nfd/nfd.sock"))
}
21 changes: 15 additions & 6 deletions face/unix-stream-listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package face
import (
"net"
"os"
"path"

"github.com/named-data/YaNFD/core"
"github.com/named-data/YaNFD/ndn"
Expand All @@ -30,10 +31,11 @@ func MakeUnixStreamListener(localURI *ndn.URI) (*UnixStreamListener, error) {
return nil, core.ErrNotCanonical
}

l := new(UnixStreamListener)
l.localURI = localURI
l.nextFD = 1
l.HasQuit = make(chan bool, 1)
l := &UnixStreamListener{
localURI: localURI,
nextFD: 1,
HasQuit: make(chan bool, 1),
}
return l, nil
}

Expand All @@ -46,14 +48,21 @@ func (l *UnixStreamListener) Run() {
// Delete any existing socket
os.Remove(l.localURI.Path())

// Create inside folder if not existing
sockPath := l.localURI.Path()
dirPath := path.Dir(sockPath)
os.MkdirAll(dirPath, os.ModePerm)
// Note: YaNFD will not link the old path /var/run/nfd.sock
// Please handle consistency yourself.

// Create listener
var err error
if l.conn, err = net.Listen(l.localURI.Scheme(), l.localURI.Path()); err != nil {
if l.conn, err = net.Listen(l.localURI.Scheme(), sockPath); err != nil {
core.LogFatal(l, "Unable to start Unix stream listener: ", err)
}

// Set permissions to allow all local apps to communicate with us
if err := os.Chmod(l.localURI.Path(), 0777); err != nil {
if err := os.Chmod(sockPath, os.ModePerm); err != nil {
core.LogFatal(l, "Unable to change permissions on Unix stream listener: ", err)
}

Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ require (
github.com/apex/log v1.9.0
github.com/cornelk/hashmap v1.0.8
github.com/google/gopacket v1.1.19
github.com/gorilla/websocket v1.5.0
github.com/gorilla/websocket v1.5.1
github.com/pelletier/go-toml v1.9.5
github.com/stretchr/testify v1.8.4
github.com/zjkmxy/go-ndn v0.0.6
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sys v0.13.0
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb
golang.org/x/sys v0.15.0
)

require (
github.com/cespare/xxhash v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.19.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7/go.mod h1:2iMrUgbbvHEiQClaW2NsSzMyGHqN+rDFqY705q49KG0=
Expand Down Expand Up @@ -73,12 +75,16 @@ golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8=
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -87,6 +93,8 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
2 changes: 1 addition & 1 deletion ndn/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestUDP(t *testing.T) {
}

func TestUnix(t *testing.T) {
uri := ndn.MakeUnixFaceURI("/run/nfd.sock")
uri := ndn.MakeUnixFaceURI("/run/nfd/nfd.sock")
assert.True(t, uri.IsCanonical())
// assert.NoError(t, uri.Canonize())
// assert.True(t, uri.IsCanonical())
Expand Down
2 changes: 1 addition & 1 deletion yanfd.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
enabled = true

# Location of the socket file
socket_path = "/run/nfd.sock"
socket_path = "/run/nfd/nfd.sock"

[faces.websocket]

Expand Down

0 comments on commit df57438

Please sign in to comment.