Skip to content

Commit fb91209

Browse files
author
chaehni
authored
redoing updates (#45)
* redoing updates * deleted comment
1 parent d664c94 commit fb91209

File tree

7 files changed

+91
-44
lines changed

7 files changed

+91
-44
lines changed

bat/bat.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ var (
5757
download bool
5858
insecureSSL bool
5959
local string // TODO: remove as soon as dispatcher supports nil local address
60-
remote string // TODO: remove as soon as RAINS is deployed
6160
auth string
6261
proxy string
6362
printV string
@@ -88,7 +87,6 @@ func init() {
8887
flag.BoolVar(&insecureSSL, "insecure", false, "Allow connections to SSL sites without certs")
8988
flag.BoolVar(&insecureSSL, "i", false, "Allow connections to SSL sites without certs")
9089
flag.StringVar(&local, "l", "", "local SCION address")
91-
flag.StringVar(&remote, "r", "", "remote SCION address")
9290
flag.StringVar(&auth, "auth", "", "HTTP authentication username:password, USER[:PASS]")
9391
flag.StringVar(&auth, "a", "", "HTTP authentication username:password, USER[:PASS]")
9492
flag.StringVar(&proxy, "proxy", "", "Proxy host and port, PROXY_URL")
@@ -123,7 +121,7 @@ func init() {
123121
}
124122

125123
// redirect SCION log to a log file
126-
slog.SetupLogFile("scion", "log", "info", 10, 10, 0)
124+
slog.SetupLogFile("scion", "log", "debug", 10, 10, 0)
127125
}
128126

129127
func parsePrintOption(s string) {
@@ -174,8 +172,7 @@ func main() {
174172
}
175173
}
176174
}
177-
// TODO: uncomment when RAINS is deployed and remove belows URL creation
178-
/* start of URL creation: Remove when RAINS is deployed*/
175+
179176
if *URL == "" {
180177
usage()
181178
}

lib/scionutil/hosts.go

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,32 @@ import (
2222
"regexp"
2323
"strings"
2424

25-
"github.com/scionproto/scion/go/lib/snet"
25+
libaddr "github.com/scionproto/scion/go/lib/addr"
2626
)
2727

28+
type scionAddress struct {
29+
ia libaddr.IA
30+
l3 libaddr.HostAddr
31+
}
32+
2833
var (
2934
hostFilePath = "/etc/hosts"
30-
addrRegexp = regexp.MustCompile(`\d{1,4}-([0-9a-f]{1,4}:){2}[0-9a-f]{1,4},\[[^]]+\]`)
31-
hosts map[string]string // hostname -> SCION address
32-
revHosts map[string][]string // SCION address w/o port -> hostnames
35+
addrRegexp = regexp.MustCompile(`^(?P<ia>\d+-[\d:A-Fa-f]+),\[(?P<host>[^\]]+)\]`)
36+
hosts map[string]scionAddress // hostname -> scionAddress
37+
revHosts map[string][]string // SCION address w/o port -> hostnames
38+
)
39+
40+
const (
41+
iaIndex = iota + 1
42+
l3Index
3343
)
3444

3545
func init() {
3646
hostsFile, err := readHostsFile()
3747
if err != nil {
3848
hostsFile = []byte{}
3949
}
40-
err = parseHostsFile(hostsFile)
50+
parseHostsFile(hostsFile)
4151
if err != nil {
4252
log.Fatal(err)
4353
}
@@ -50,28 +60,23 @@ func AddHost(hostname, address string) error {
5060
if addrs, ok := hosts[hostname]; ok {
5161
return fmt.Errorf("Host %q already exists, address(es): %v", hostname, addrs)
5262
}
53-
_, err := snet.AddrFromString(fmt.Sprintf("%s:%s", address, "0"))
63+
addr, err := addrFromString(address)
5464
if err != nil {
5565
return fmt.Errorf("Cannot add host %q: %v", hostname, err)
5666
}
57-
hosts[hostname] = address
67+
hosts[hostname] = addr
5868
revHosts[address] = append(revHosts[address], hostname)
5969

6070
return nil
6171
}
6272

63-
// GetHostByName returns the SCION address corresponding to hostname.
64-
// The port is set to the default zero value.
65-
func GetHostByName(hostname string) (*snet.Addr, error) {
73+
// GetHostByName returns the IA and HostAddr corresponding to hostname
74+
func GetHostByName(hostname string) (libaddr.IA, libaddr.HostAddr, error) {
6675
addr, ok := hosts[hostname]
6776
if !ok {
68-
return nil, fmt.Errorf("Address for host %q not found", hostname)
77+
return libaddr.IA{}, nil, fmt.Errorf("Address for host %q not found", hostname)
6978
}
70-
scionAddr, err := snet.AddrFromString(addr)
71-
if err != nil {
72-
return nil, err
73-
}
74-
return scionAddr, nil
79+
return addr.ia, addr.l3, nil
7580
}
7681

7782
// GetHostnamesByAddress returns the hostnames corresponding to address
@@ -92,24 +97,47 @@ func readHostsFile() ([]byte, error) {
9297
return bs, nil
9398
}
9499

95-
func parseHostsFile(hostsFile []byte) error {
96-
hosts = make(map[string]string)
100+
func parseHostsFile(hostsFile []byte) {
101+
hosts = make(map[string]scionAddress)
97102
revHosts = make(map[string][]string)
98103
lines := bytes.Split(hostsFile, []byte("\n"))
99104
for _, line := range lines {
100105
fields := strings.Fields(string(line))
101106
if len(fields) == 0 {
102107
continue
103108
}
104-
if match := addrRegexp.FindString(fields[0]); len(match) == len(fields[0]) {
109+
if matched := addrRegexp.MatchString(fields[0]); matched {
110+
addr, err := addrFromString(fields[0])
111+
if err != nil {
112+
continue
113+
}
114+
115+
// map hostnames to scionAddress
105116
for _, field := range fields[1:] {
106117
if _, ok := hosts[field]; !ok {
107-
hosts[field] = fields[0]
118+
hosts[field] = addr
108119
revHosts[fields[0]] = append(revHosts[fields[0]], field)
109120
}
110121
}
111122
}
112123

113124
}
114-
return nil
125+
}
126+
127+
func addrFromString(addr string) (scionAddress, error) {
128+
parts := addrRegexp.FindStringSubmatch(addr)
129+
ia, err := libaddr.IAFromString(parts[iaIndex])
130+
if err != nil {
131+
return scionAddress{}, fmt.Errorf("Invalid IA string: %v", parts[iaIndex])
132+
}
133+
var l3 libaddr.HostAddr
134+
if hostSVC := libaddr.HostSVCFromString(parts[l3Index]); hostSVC != libaddr.SvcNone {
135+
l3 = hostSVC
136+
} else {
137+
l3 = libaddr.HostFromIPStr(parts[l3Index])
138+
if l3 == nil {
139+
return scionAddress{}, fmt.Errorf("Invalid IP address string: %v", parts[l3Index])
140+
}
141+
}
142+
return scionAddress{ia, l3}, nil
115143
}

lib/scionutil/hosts_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ func TestAddingHost(t *testing.T) {
6868
}
6969

7070
func TestReadHosts(t *testing.T) {
71-
addr, err := GetHostByName("host1.2")
71+
ia, l3, err := GetHostByName("host1.2")
7272
if err != nil {
7373
t.Error(err)
7474
}
75-
addr.Host.L4 = libaddr.NewL4UDPInfo(0)
75+
addr := &snet.Addr{IA: ia, Host: &libaddr.AppAddr{L3: l3, L4: libaddr.NewL4UDPInfo(0)}}
76+
7677
expected, err := snet.AddrFromString("17-ffaa:0:1,[192.168.1.1]:0")
7778
if err != nil {
7879
panic("This should always work")
@@ -82,18 +83,19 @@ func TestReadHosts(t *testing.T) {
8283
}
8384

8485
// works with IPv6 SCION hosts
85-
addr, err = GetHostByName("host4")
86+
ia, l3, err = GetHostByName("host4")
8687
if err != nil {
8788
t.Error(err)
8889
}
89-
addr.Host.L4 = libaddr.NewL4UDPInfo(0)
90+
addr = &snet.Addr{IA: ia, Host: &libaddr.AppAddr{L3: l3, L4: libaddr.NewL4UDPInfo(0)}}
91+
9092
expected, err = snet.AddrFromString("20-ffaa:c0ff:ee12,[::ff1:ce00:dead:10cc:baad:f00d]:0")
9193
if !addr.EqAddr(expected) {
9294
t.Errorf("host resolved to wrong address, expected: %q, received: %q", "20-ffaa:c0ff:ee12,[::ff1:ce00:dead:10cc:baad:f00d]:0", addr)
9395
}
9496

9597
// does not parse commented hosts
96-
addr, err = GetHostByName("commented")
98+
ia, l3, err = GetHostByName("commented")
9799
if err == nil {
98100
t.Error("read commented host")
99101
}
@@ -114,7 +116,7 @@ func TestReadAddresses(t *testing.T) {
114116
t.Error(err)
115117
}
116118
if len(addrs) != 3 || addrs[0] != "host1.1" || addrs[1] != "host1.2" || addrs[2] != "host3" {
117-
t.Errorf("address resolved to wrong hostnames, expected: %v, received: %v", []string{"host1", "host3"}, addrs)
119+
t.Errorf("address resolved to wrong hostnames, expected: %v, received: %v", []string{"host1.1", "host1.2", "host3"}, addrs)
118120
}
119121

120122
// pass address with IPv6

lib/scionutil/hosts_test_file

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fe80:cd00:0:cde:1257:0:211e:729c dummy2
77
123:4567:89ab:cdef:123:4567:89ab:cdef dummy3
88

99
# SCION hosts
10-
# 17-ffaa:0:0,[10.0.8.15] commented
10+
#17-ffaa:0:0,[10.0.8.15] commented
1111
17-ffaa:0:1,[192.168.1.1] host1.1 host1.2
1212
18-ffaa:1:2,[10.0.8.10] host2
1313
17-ffaa:0:1,[192.168.1.1] host3

lib/shttp/examples/image_server/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ func main() {
4141
log.Fatal(err)
4242
}
4343

44-
rAddr, err := scionutil.GetHostByName("image-server")
44+
ia, l3, err := scionutil.GetHostByName("image-server")
4545
if err != nil {
4646
log.Fatal(err)
4747
}
48-
rAddr.Host.L4 = addr.NewL4UDPInfo(40002)
48+
l4 := addr.NewL4UDPInfo(40002)
49+
rAddr := &snet.Addr{IA: ia, Host: &addr.AppAddr{L3: l3, L4: l4}}
50+
4951
if *interactive {
5052
scionutil.ChoosePathInteractive(lAddr, rAddr)
5153
} else {

lib/shttp/examples/minimal/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ func main() {
4141
log.Fatal(err)
4242
}
4343

44-
rAddr, err := scionutil.GetHostByName("minimal-server")
44+
ia, l3, err := scionutil.GetHostByName("minimal-server")
4545
if err != nil {
4646
log.Fatal(err)
4747
}
48-
rAddr.Host.L4 = addr.NewL4UDPInfo(40002)
48+
l4 := addr.NewL4UDPInfo(40002)
49+
rAddr := &snet.Addr{IA: ia, Host: &addr.AppAddr{L3: l3, L4: l4}}
50+
4951
if *interactive {
5052
scionutil.ChoosePathInteractive(lAddr, rAddr)
5153
} else {

lib/shttp/transport.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ import (
3232
"github.com/scionproto/scion/go/lib/snet/squic"
3333
)
3434

35-
// Transport wraps a h2quic.RoundTripper and makes it compatible with SCION
35+
// Transport wraps a h2quic.RoundTripper making it compatible with SCION
3636
type Transport struct {
37-
LAddr *snet.Addr
37+
LAddr *snet.Addr
38+
QuicConfig *quic.Config
39+
DisableCompression bool
3840

3941
rt *h2quic.RoundTripper
4042

@@ -60,26 +62,40 @@ func (t *Transport) RoundTripOpt(req *http.Request, opt h2quic.RoundTripOpt) (*h
6062
return nil, initErr
6163
}
6264

63-
// set the dial function once for each Transport
65+
// set the dial function and QuicConfig once for each Transport
6466
t.dialOnce.Do(func() {
6567
dial := func(network, addr string, tlsCfg *tls.Config, cfg *quic.Config) (quic.Session, error) {
68+
69+
/* TODO(chaehni):
70+
RequestConnectionIDOmission MUST not be set to 'true' when a connection is dialed using an existing net.PacketConn
71+
(which the squic package is doing)
72+
quic-go/client.go func populateClientConfig (line 177) fails to catch this problem
73+
As a result, if set to 'true' the quic-go client multiplexer fails to match incoming packets
74+
This problem is solved in subsequent releases of quic-go (>v0.8.0)
75+
See issue https://github.com/scionproto/scion/issues/2463
76+
*/
77+
cfg.RequestConnectionIDOmission = false
78+
6679
host, port, err := net.SplitHostPort(addr)
6780
if err != nil {
6881
return nil, err
6982
}
70-
raddr, err := scionutil.GetHostByName(host)
83+
ia, l3, err := scionutil.GetHostByName(host)
7184
if err != nil {
7285
return nil, err
7386
}
7487
p, err := strconv.ParseUint(port, 10, 16)
7588
if err != nil {
7689
p = 443
7790
}
78-
raddr.Host.L4 = libaddr.NewL4UDPInfo(uint16(p))
79-
return squic.DialSCION(nil, t.LAddr, raddr, nil)
91+
l4 := libaddr.NewL4UDPInfo(uint16(p))
92+
raddr := &snet.Addr{IA: ia, Host: &libaddr.AppAddr{L3: l3, L4: l4}}
93+
return squic.DialSCION(nil, t.LAddr, raddr, cfg)
8094
}
8195
t.rt = &h2quic.RoundTripper{
82-
Dial: dial,
96+
Dial: dial,
97+
QuicConfig: t.QuicConfig,
98+
DisableCompression: t.DisableCompression,
8399
}
84100
})
85101

0 commit comments

Comments
 (0)