Skip to content

Commit 2f0a737

Browse files
authored
Update to scion master, adapt to changed API (#135)
* Update to scion master, adapt to changed API Adapt use of `snet.Conn` type (no longer an interface, but a struct). Adapt use of renamed `UDPAddrFromString`, now `ParseUDPAddr`. Use some new helper functions added in scion (`sciondConn.LocalIA` and `snet/addrutil.ResolveLocal`). Misc cleanup; handle previously ignored error for finding local IP, add timeout to sciond connection and queries during initialization. Update rains after merging equivalent netsec-ethz/rains#235. * Cleanup docs and README
1 parent 5e9c626 commit 2f0a737

File tree

15 files changed

+72
-81
lines changed

15 files changed

+72
-81
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ The dispatcher and sciond sockets are assumed to be at default locations, but
6262
this can be overriden using environment variables:
6363

6464
SCION_DISPATCHER_SOCKET: /run/shm/dispatcher/default.sock
65-
SCION_DEAMON_SOCKET: /run/shm/sciond/default.sock
65+
SCION_DAEMON_ADDRESS: 127.0.0.1:30255
6666

6767
This is convenient for the normal use case of running a the endhost stack for a
6868
single SCION AS.
69-
When running multiple local ASes, e.g. during development, the path to the
69+
When running multiple local ASes, e.g. during development, the address of the
7070
sciond corresponding to the desired AS needs to be specified in the
71-
`SCION_DEAMON_SOCKET` environment variable.
71+
`SCION_DAEMON_ADDRESS` environment variable.
72+
In this case, the different sciond addresses can be found in their
73+
corresponding `sd.toml` configuration files in the `gen/ISDx/ASy/endhost`
74+
directory, or summarized in the file `gen/sciond_addresses.json`.
7275

7376

7477
#### Hostnames

bwtester/bwtestclient/bwtestclient.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ func main() {
259259
serverCCAddrStr string
260260
serverCCAddr *snet.UDPAddr
261261
// Control channel connection
262-
CCConn snet.Conn
262+
CCConn *snet.Conn
263263
// Data channel connection
264-
DCConn snet.Conn
264+
DCConn *snet.Conn
265265

266266
clientBwpStr string
267267
clientBwp BwtestParameters

bwtester/bwtestlib/bwtestlib.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func DecodeBwtestParameters(buf []byte) (*BwtestParameters, int, error) {
159159
return &v, is - bb.Len(), err
160160
}
161161

162-
func HandleDCConnSend(bwp *BwtestParameters, udpConnection snet.Conn) {
162+
func HandleDCConnSend(bwp *BwtestParameters, udpConnection *snet.Conn) {
163163
sb := make([]byte, bwp.PacketSize)
164164
var i int64 = 0
165165
t0 := time.Now()
@@ -191,7 +191,7 @@ func HandleDCConnSend(bwp *BwtestParameters, udpConnection snet.Conn) {
191191
}
192192
}
193193

194-
func HandleDCConnReceive(bwp *BwtestParameters, udpConnection snet.Conn, res *BwtestResult, resLock *sync.Mutex, done *sync.Mutex) {
194+
func HandleDCConnReceive(bwp *BwtestParameters, udpConnection *snet.Conn, res *BwtestResult, resLock *sync.Mutex, done *sync.Mutex) {
195195
resLock.Lock()
196196
finish := res.ExpectedFinishTime
197197
resLock.Unlock()

bwtester/bwtestserver/bwtestserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func runServer(port uint16) error {
103103
return nil
104104
}
105105

106-
func handleClients(CCConn snet.Conn, receivePacketBuffer []byte, sendPacketBuffer []byte) {
106+
func handleClients(CCConn *snet.Conn, receivePacketBuffer []byte, sendPacketBuffer []byte) {
107107

108108
for {
109109
// Handle client requests

camerapp/imagefetcher/imagefetcher.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func check(e error) {
4747
}
4848
}
4949

50-
func fetchFileInfo(udpConnection snet.Conn) (string, uint32, time.Duration, error) {
50+
func fetchFileInfo(udpConnection *snet.Conn) (string, uint32, time.Duration, error) {
5151
numRetries := 0
5252
packetBuffer := make([]byte, 2500)
5353

@@ -103,7 +103,7 @@ func fetchFileInfo(udpConnection snet.Conn) (string, uint32, time.Duration, erro
103103
return "", 0, 0, fmt.Errorf("could not obtain file information")
104104
}
105105

106-
func blockFetcher(fetchBlockChan chan uint32, udpConnection snet.Conn, fileName string, fileSize uint32) {
106+
func blockFetcher(fetchBlockChan chan uint32, udpConnection *snet.Conn, fileName string, fileSize uint32) {
107107
packetBuffer := make([]byte, 512)
108108
packetBuffer[0] = 'G'
109109
packetBuffer[1] = byte(len(fileName))
@@ -122,7 +122,7 @@ func blockFetcher(fetchBlockChan chan uint32, udpConnection snet.Conn, fileName
122122
}
123123
}
124124

125-
func blockReceiver(receivedBlockChan chan uint32, udpConnection snet.Conn, fileBuffer []byte, fileSize uint32) {
125+
func blockReceiver(receivedBlockChan chan uint32, udpConnection *snet.Conn, fileBuffer []byte, fileSize uint32) {
126126
packetBuffer := make([]byte, 2500)
127127
for {
128128
n, _, err := udpConnection.ReadFrom(packetBuffer)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ require (
1313
github.com/lucas-clemente/quic-go v0.7.1-0.20190212114006-fd7246d7ed6e
1414
github.com/mattn/go-sqlite3 v1.9.1-0.20180719091609-b3511bfdd742
1515
github.com/msteinert/pam v0.0.0-20190215180659-f29b9f28d6f9
16-
github.com/netsec-ethz/rains v0.0.0-20200305191422-58aacbeca9a9
17-
github.com/scionproto/scion v0.4.1-0.20200302170049-bf51fb3769f5
16+
github.com/netsec-ethz/rains v0.0.0-20200326150705-3eb858e82188
17+
github.com/scionproto/scion v0.4.1-0.20200324160848-64e5ff95eec1
1818
github.com/smartystreets/goconvey v1.6.4
1919
golang.org/x/crypto v0.0.0-20190909091759-094676da4a83
2020
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8

go.sum

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,22 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
9696
github.com/msteinert/pam v0.0.0-20190215180659-f29b9f28d6f9 h1:ZivaaKmjs9q90zi6I4gTLW6tbVGtlBjellr3hMYaly0=
9797
github.com/msteinert/pam v0.0.0-20190215180659-f29b9f28d6f9/go.mod h1:np1wUFZ6tyoke22qDJZY40URn9Ae51gX7ljIWXN5TJs=
9898
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
99-
github.com/netsec-ethz/rains v0.0.0-20200305191422-58aacbeca9a9 h1:TMOZXc9IvUtyu1NydhN3PofWQGWeLKMeSId/73ZbLqU=
100-
github.com/netsec-ethz/rains v0.0.0-20200305191422-58aacbeca9a9/go.mod h1:M0seLcpjvJ9XrAgx4vnkFseaoottkErWIrVBF+le3P0=
99+
github.com/netsec-ethz/rains v0.0.0-20200326150705-3eb858e82188 h1:Au1nAi8Ekr8IVXtFDR67Pg/CPDPTAAPWgEiiRXGZo7U=
100+
github.com/netsec-ethz/rains v0.0.0-20200326150705-3eb858e82188/go.mod h1:TKDRuFhFlQsDR+6vhQa7YwIUaeEcuK4bmFpN1YemAxA=
101101
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
102102
github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY=
103103
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
104104
github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ=
105105
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
106106
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
107107
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
108-
github.com/patrickmn/go-cache v2.1.1-0.20180815053127-5633e0862627+incompatible h1:MUIwjEiAMYk8zkXXUQeb5itrXF+HpS2pfxNsA2a7AiY=
109108
github.com/patrickmn/go-cache v2.1.1-0.20180815053127-5633e0862627+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
110109
github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ=
111110
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
112111
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
113-
github.com/pkg/errors v0.8.2-0.20190227000051-27936f6d90f9 h1:PCj9X21C4pet4sEcElTfAi6LSl5ShkjE8doieLc+cbU=
114112
github.com/pkg/errors v0.8.2-0.20190227000051-27936f6d90f9/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
115113
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
116114
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
117-
github.com/prometheus/client_golang v0.9.1 h1:K47Rk0v/fkEfwfQet2KWhscE0cJzjgCCDBG2KHZoVno=
118115
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
119116
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
120117
github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8=
@@ -126,13 +123,12 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
126123
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
127124
github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo=
128125
github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc=
129-
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d h1:GoAlyOgbOEIFdaDqxJVlbOQ1DtGmZWs/Qau0hIlk+WQ=
130126
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
131127
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
132128
github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE=
133129
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
134-
github.com/scionproto/scion v0.4.1-0.20200302170049-bf51fb3769f5 h1:aVX6gM9dRRS3i0Qhpdf1tT86DBTAmr7glR3aRg8He1c=
135-
github.com/scionproto/scion v0.4.1-0.20200302170049-bf51fb3769f5/go.mod h1:yayLUQzSt/Lwg+3dA2terZ3tEgXI9r7CX8MKrX5CIdI=
130+
github.com/scionproto/scion v0.4.1-0.20200324160848-64e5ff95eec1 h1:dEWLk21ts5TMiIpiPql0+G5j+IwyqSu/0W2sY29XoAk=
131+
github.com/scionproto/scion v0.4.1-0.20200324160848-64e5ff95eec1/go.mod h1:yayLUQzSt/Lwg+3dA2terZ3tEgXI9r7CX8MKrX5CIdI=
136132
github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
137133
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
138134
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
@@ -178,21 +174,18 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
178174
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
179175
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
180176
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
181-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
182177
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
183178
golang.org/x/net v0.0.0-20191105084925-a882066a44e0 h1:QPlSTtPE2k6PZPasQUbzuK3p9JbS+vMXYVto8g/yrsg=
184179
golang.org/x/net v0.0.0-20191105084925-a882066a44e0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
185180
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
186181
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
187182
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
188-
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
189183
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
190184
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
191185
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
192186
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
193187
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
194188
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
195-
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
196189
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
197190
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 h1:4y9KwBHBgBNwDbtu44R5o1fdOCQUEXhbk/P4A9WmJq0=
198191
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -203,7 +196,6 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3
203196
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
204197
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c h1:IGkKhmfzcztjm6gYkykvu/NiS8kaqbCWAEWWAyf8J5U=
205198
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
206-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
207199
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
208200
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
209201
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=

pkg/appnet/appnet.go

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ be overridden using environment variables:
2727
SCION_DISPATCHER_SOCKET: /run/shm/dispatcher/default.sock
2828
SCION_DAEMON_ADDRESS: 127.0.0.1:30255
2929
30-
This is convenient for the normal use case of running a the endhost stack for
31-
a single SCION AS. When running multiple local ASes, e.g. during development, the path
32-
to the sciond corresponding to the desired AS needs to be specified in the
33-
SCION_DAEMON_ADDRESS environment variable.
30+
This is convenient for the normal use case of running a the endhost stack for a
31+
single SCION AS. When running multiple local ASes, e.g. during development, the
32+
address of the sciond corresponding to the desired AS needs to be specified in
33+
the SCION_DAEMON_ADDRESS environment variable.
3434
3535
3636
Wildcard IP Addresses
@@ -55,10 +55,12 @@ import (
5555
"net"
5656
"os"
5757
"sync"
58+
"time"
5859

5960
"github.com/scionproto/scion/go/lib/addr"
6061
"github.com/scionproto/scion/go/lib/sciond"
6162
"github.com/scionproto/scion/go/lib/snet"
63+
"github.com/scionproto/scion/go/lib/snet/addrutil"
6264
"github.com/scionproto/scion/go/lib/sock/reliable"
6365
)
6466

@@ -73,6 +75,10 @@ type Network struct {
7375
hostInLocalAS net.IP
7476
}
7577

78+
const (
79+
initTimeout = 1 * time.Second
80+
)
81+
7682
var defNetwork Network
7783
var initOnce sync.Once
7884

@@ -87,7 +93,7 @@ func DefNetwork() *Network {
8793
// Dial connects to the address (on the SCION/UDP network).
8894
// The address can be of the form of a SCION address (i.e. of the form "ISD-AS,[IP]:port")
8995
// or in the form of hostname:port.
90-
func Dial(address string) (snet.Conn, error) {
96+
func Dial(address string) (*snet.Conn, error) {
9197
raddr, err := ResolveUDPAddr(address)
9298
if err != nil {
9399
return nil, err
@@ -102,51 +108,58 @@ func Dial(address string) (snet.Conn, error) {
102108
// support long lived connections well, as the path *will* expire.
103109
// This is all that snet currently provides, we'll need to add a layer on top
104110
// that updates the paths in case they expire or are revoked.
105-
func DialAddr(raddr *snet.UDPAddr) (snet.Conn, error) {
111+
func DialAddr(raddr *snet.UDPAddr) (*snet.Conn, error) {
106112
if raddr.Path == nil {
107113
err := SetDefaultPath(raddr)
108114
if err != nil {
109115
return nil, err
110116
}
111117
}
112-
laddr := &net.UDPAddr{IP: localIP(raddr)}
113-
return DefNetwork().Dial(context.TODO(), "udp", laddr, raddr, addr.SvcNone)
118+
localIP, err := resolveLocal(raddr)
119+
if err != nil {
120+
return nil, err
121+
}
122+
laddr := &net.UDPAddr{IP: localIP}
123+
return DefNetwork().Dial(context.Background(), "udp", laddr, raddr, addr.SvcNone)
114124
}
115125

116126
// Listen acts like net.ListenUDP in a SCION network.
117127
// The listen address or parts of it may be nil or unspecified, signifying to
118128
// listen on a wildcard address.
119129
//
120130
// See note on wildcard addresses in the package documentation.
121-
func Listen(listen *net.UDPAddr) (snet.Conn, error) {
131+
func Listen(listen *net.UDPAddr) (*snet.Conn, error) {
122132
if listen == nil {
123133
listen = &net.UDPAddr{}
124134
}
125135
if listen.IP == nil || listen.IP.IsUnspecified() {
126-
listen = &net.UDPAddr{IP: defaultLocalIP(), Port: listen.Port, Zone: listen.Zone}
136+
localIP, err := defaultLocalIP()
137+
if err != nil {
138+
return nil, err
139+
}
140+
listen = &net.UDPAddr{IP: localIP, Port: listen.Port, Zone: listen.Zone}
127141
}
128-
return DefNetwork().Listen(context.TODO(), "udp", listen, addr.SvcNone)
142+
return DefNetwork().Listen(context.Background(), "udp", listen, addr.SvcNone)
129143
}
130144

131145
// ListenPort is a shortcut to Listen on a specific port with a wildcard IP address.
132146
//
133147
// See note on wildcard addresses in the package documentation.
134-
func ListenPort(port uint16) (snet.Conn, error) {
135-
listen := &net.UDPAddr{IP: defaultLocalIP(), Port: int(port)}
136-
return DefNetwork().Listen(context.TODO(), "udp", listen, addr.SvcNone)
148+
func ListenPort(port uint16) (*snet.Conn, error) {
149+
return Listen(&net.UDPAddr{Port: int(port)})
137150
}
138151

139-
// localAddr returns the source IP address for traffic to raddr. If
152+
// resolveLocal returns the source IP address for traffic to raddr. If
140153
// raddr.NextHop is set, it's used to determine the local IP address.
141154
// Otherwise, the default local IP address is returned.
142155
//
143156
// The purpose of this function is to workaround not being able to bind to
144157
// wildcard addresses in snet.
145158
// See note on wildcard addresses in the package documentation.
146-
func localIP(raddr *snet.UDPAddr) net.IP {
159+
func resolveLocal(raddr *snet.UDPAddr) (net.IP, error) {
147160
if raddr.NextHop != nil {
148161
nextHop := raddr.NextHop.IP
149-
return findSrcIP(nextHop)
162+
return addrutil.ResolveLocal(nextHop)
150163
}
151164
return defaultLocalIP()
152165
}
@@ -156,8 +169,8 @@ func localIP(raddr *snet.UDPAddr) net.IP {
156169
// The purpose of this function is to workaround not being able to bind to
157170
// wildcard addresses in snet.
158171
// See note on wildcard addresses in the package documentation.
159-
func defaultLocalIP() net.IP {
160-
return findSrcIP(DefNetwork().hostInLocalAS)
172+
func defaultLocalIP() (net.IP, error) {
173+
return addrutil.ResolveLocal(DefNetwork().hostInLocalAS)
161174
}
162175

163176
func mustInitDefNetwork() {
@@ -169,19 +182,21 @@ func mustInitDefNetwork() {
169182
}
170183

171184
func initDefNetwork() error {
185+
ctx, cancel := context.WithTimeout(context.Background(), initTimeout)
186+
defer cancel()
172187
dispatcher, err := findDispatcher()
173188
if err != nil {
174189
return err
175190
}
176-
sciondConn, err := findSciond()
191+
sciondConn, err := findSciond(ctx)
177192
if err != nil {
178193
return err
179194
}
180-
localIA, err := findLocalIA(sciondConn)
195+
localIA, err := sciondConn.LocalIA(ctx)
181196
if err != nil {
182197
return err
183198
}
184-
hostInLocalAS, err := findAnyHostInLocalAS(sciondConn)
199+
hostInLocalAS, err := findAnyHostInLocalAS(ctx, sciondConn)
185200
if err != nil {
186201
return err
187202
}
@@ -196,12 +211,12 @@ func initDefNetwork() error {
196211
return nil
197212
}
198213

199-
func findSciond() (sciond.Connector, error) {
214+
func findSciond(ctx context.Context) (sciond.Connector, error) {
200215
address, ok := os.LookupEnv("SCION_DAEMON_ADDRESS")
201216
if !ok {
202217
address = sciond.DefaultSCIONDAddress
203218
}
204-
sciondConn, err := sciond.NewService(address).Connect(context.Background())
219+
sciondConn, err := sciond.NewService(address).Connect(ctx)
205220
if err != nil {
206221
return nil, fmt.Errorf("unable to connect to SCIOND at %s (override with SCION_DAEMON_ADDRESS): %w", address, err)
207222
}
@@ -244,28 +259,9 @@ func isSocket(mode os.FileMode) bool {
244259
return mode&os.ModeSocket != 0
245260
}
246261

247-
func findLocalIA(sciondConn sciond.Connector) (addr.IA, error) {
248-
asInfo, err := sciondConn.ASInfo(context.TODO(), addr.IA{})
249-
if err != nil {
250-
return addr.IA{}, err
251-
}
252-
ia := asInfo.Entries[0].RawIsdas.IA()
253-
return ia, nil
254-
}
255-
256-
// findSrcIP returns the src IP used for traffic destined to dst
257-
func findSrcIP(dst net.IP) net.IP {
258-
// Use net.Dial to lookup source address. Alternatively, could use netlink.
259-
udpAddr := net.UDPAddr{IP: dst, Port: 1}
260-
udpConn, _ := net.DialUDP(udpAddr.Network(), nil, &udpAddr)
261-
srcIP := udpConn.LocalAddr().(*net.UDPAddr).IP
262-
udpConn.Close()
263-
return srcIP
264-
}
265-
266262
// findAnyHostInLocalAS returns the IP address of some (infrastructure) host in the local AS.
267-
func findAnyHostInLocalAS(sciondConn sciond.Connector) (net.IP, error) {
268-
addr, err := sciond.TopoQuerier{Connector: sciondConn}.OverlayAnycast(context.Background(), addr.SvcBS)
263+
func findAnyHostInLocalAS(ctx context.Context, sciondConn sciond.Connector) (net.IP, error) {
264+
addr, err := sciond.TopoQuerier{Connector: sciondConn}.OverlayAnycast(ctx, addr.SvcBS)
269265
if err != nil {
270266
return nil, err
271267
}

pkg/appnet/appquic/appquic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var (
4141
// the close-the-socket behaviour of quic.DialAddr.
4242
type closerSession struct {
4343
quic.Session
44-
conn snet.Conn
44+
conn *snet.Conn
4545
}
4646

4747
func (s *closerSession) Close() error {

pkg/appnet/hosts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func SplitHostPort(hostport string) (host, port string, err error) {
8080
// The address can be of the form of a SCION address (i.e. of the form "ISD-AS,[IP]:port")
8181
// or in the form of "hostname:port".
8282
func ResolveUDPAddr(address string) (*snet.UDPAddr, error) {
83-
raddr, err := snet.UDPAddrFromString(address)
83+
raddr, err := snet.ParseUDPAddr(address)
8484
if err == nil {
8585
return raddr, nil
8686
}

0 commit comments

Comments
 (0)