Skip to content

Commit 3ea0e44

Browse files
committed
scionutil: use "sciondFromIA" logic if no default.sock
Seems simple enough, no need to specify this flag explicitly. Note that the fallback could be either way (i.e. prefer default.sock or prefer ia-specific name), as these cases are typically exclusive (either running single AS or local topology with many ASes). This change allows to run e.g. lib/shttp/examples/minimal on a local topology.
1 parent cc035d1 commit 3ea0e44

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/scionutil/initialization.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
package scionutil
1616

1717
import (
18+
"github.com/scionproto/scion/go/lib/addr"
1819
"github.com/scionproto/scion/go/lib/sciond"
1920
"github.com/scionproto/scion/go/lib/snet"
21+
"os"
2022
)
2123

2224
// InitSCION initializes the default SCION networking context with the provided SCION address
2325
// and the default SCIOND/SCION dispatcher
2426
func InitSCION(localAddr *snet.Addr) error {
25-
err := snet.Init(localAddr.IA, GetDefaultSCIOND(), GetDefaultDispatcher())
27+
err := snet.Init(localAddr.IA, GetSCIONDPath(&localAddr.IA), GetDefaultDispatcher())
2628
if err != nil {
2729
return err
2830
}
@@ -37,17 +39,23 @@ func InitSCIONString(localAddr string) (*snet.Addr, error) {
3739
return nil, err
3840
}
3941

40-
err = snet.Init(addr.IA, GetDefaultSCIOND(), GetDefaultDispatcher())
42+
err = snet.Init(addr.IA, GetSCIONDPath(&addr.IA), GetDefaultDispatcher())
4143
if err != nil {
4244
return nil, err
4345
}
4446

4547
return addr, nil
4648
}
4749

48-
// GetDefaultSCIOND returns the path to the default SCION socket
49-
func GetDefaultSCIOND() string {
50-
return sciond.GetDefaultSCIONDPath(nil)
50+
// GetSCIONDPath returns the path to the SCION socket.
51+
func GetSCIONDPath(ia *addr.IA) string {
52+
53+
// Use default.sock if exists:
54+
if _, err := os.Stat(sciond.DefaultSCIONDPath); err == nil {
55+
return sciond.DefaultSCIONDPath
56+
}
57+
// otherwise, use socket with ia name:
58+
return sciond.GetDefaultSCIONDPath(ia)
5159
}
5260

5361
// GetDefaultDispatcher returns the path to the default SCION dispatcher

0 commit comments

Comments
 (0)