Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up host type in SCIOND-API RPC messages #3233

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/integration/cert_req/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (c client) requestTRC(chain *cert.Chain) error {

func getRemote() error {
// Fetch address of service
var hostInfo *hostinfo.HostInfo
var hostInfo *hostinfo.Host
var err error
if hostInfo, err = getSVCAddress(); err != nil {
return err
Expand All @@ -178,7 +178,7 @@ func getRemote() error {
return nil
}

func getSVCAddress() (*hostinfo.HostInfo, error) {
func getSVCAddress() (*hostinfo.Host, error) {
connector := snet.DefNetwork.Sciond()
ctx, cancelF := context.WithTimeout(context.Background(), integration.DefaultIOTimeout)
defer cancelF()
Expand Down
64 changes: 32 additions & 32 deletions go/lib/hostinfo/hostinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,66 +26,69 @@ import (
"github.com/scionproto/scion/go/lib/topology"
)

// HostInfo contains connectivity information for a host.
type HostInfo struct {
Port uint16
Addrs struct {
Ipv4 []byte
Ipv6 []byte
}
// Host contains connectivity information for a host.
type Host struct {
Addrs Addrs `capnp:"addrs"`
Port uint16 `capnp:"port"`
}

// Addrs is an address union for use in capnp serializations.
type Addrs struct {
IPv4 []byte `capnp:"ipv4"`
IPv6 []byte `capnp:"ipv6"`
}

func FromHostAddr(host addr.HostAddr, port uint16) *HostInfo {
h := &HostInfo{Port: port}
func FromHostAddr(host addr.HostAddr, port uint16) *Host {
h := &Host{Port: port}
if host.Type() == addr.HostTypeIPv4 {
h.Addrs.Ipv4 = host.IP()
h.Addrs.IPv4 = host.IP()
} else {
h.Addrs.Ipv6 = host.IP()
h.Addrs.IPv6 = host.IP()
}
return h
}

func FromTopoAddr(topoAddr topology.TopoAddr) HostInfo {
func FromTopoAddr(topoAddr topology.TopoAddr) Host {
ipv4, port4 := topoAddrToIPv4AndPort(topoAddr)
ipv6, port6 := topoAddrToIPv6AndPort(topoAddr)
return buildHostInfo(ipv4, ipv6, port4, port6)
}

func FromTopoBRAddr(topoBRAddr topology.TopoBRAddr) HostInfo {
func FromTopoBRAddr(topoBRAddr topology.TopoBRAddr) Host {
ipv4, port4 := topoBRAddrToIPv4AndPort(topoBRAddr)
ipv6, port6 := topoBRAddrToIPv6AndPort(topoBRAddr)
return buildHostInfo(ipv4, ipv6, port4, port6)
}

func (h *HostInfo) Host() addr.HostAddr {
if len(h.Addrs.Ipv4) > 0 {
return addr.HostIPv4(h.Addrs.Ipv4)
func (h *Host) Host() addr.HostAddr {
if len(h.Addrs.IPv4) > 0 {
return addr.HostIPv4(h.Addrs.IPv4)
}
if len(h.Addrs.Ipv6) > 0 {
return addr.HostIPv6(h.Addrs.Ipv6)
if len(h.Addrs.IPv6) > 0 {
return addr.HostIPv6(h.Addrs.IPv6)
}
return nil
}

func (h *HostInfo) Overlay() (*overlay.OverlayAddr, error) {
func (h *Host) Overlay() (*overlay.OverlayAddr, error) {
var l4 addr.L4Info
if h.Port != 0 {
l4 = addr.NewL4UDPInfo(h.Port)
}
return overlay.NewOverlayAddr(h.Host(), l4)
}

func (h *HostInfo) Copy() *HostInfo {
func (h *Host) Copy() *Host {
if h == nil {
return nil
}
res := &HostInfo{Port: h.Port}
res.Addrs.Ipv4 = common.CloneByteSlice(h.Addrs.Ipv4)
res.Addrs.Ipv6 = common.CloneByteSlice(h.Addrs.Ipv6)
res := &Host{Port: h.Port}
res.Addrs.IPv4 = common.CloneByteSlice(h.Addrs.IPv4)
res.Addrs.IPv6 = common.CloneByteSlice(h.Addrs.IPv6)
return res
}

func (h *HostInfo) String() string {
func (h *Host) String() string {
return fmt.Sprintf("[%v]:%d", h.Host(), h.Port)
}

Expand Down Expand Up @@ -124,7 +127,7 @@ func topoBRAddrToIPv6AndPort(topoBRAddr topology.TopoBRAddr) (net.IP, uint16) {
return nil, 0
}

func buildHostInfo(ipv4, ipv6 net.IP, port4, port6 uint16) HostInfo {
func buildHostInfo(ipv4, ipv6 net.IP, port4, port6 uint16) Host {
if port4 != 0 && port6 != 0 && port4 != port6 {
// NOTE: https://github.com/scionproto/scion/issues/1842 will change
// the behavior of this.
Expand All @@ -135,13 +138,10 @@ func buildHostInfo(ipv4, ipv6 net.IP, port4, port6 uint16) HostInfo {
if port == 0 {
port = port6
}
return HostInfo{
Addrs: struct {
Ipv4 []byte
Ipv6 []byte
}{
Ipv4: ipv4,
Ipv6: ipv6,
return Host{
Addrs: Addrs{
IPv4: ipv4,
IPv6: ipv6,
},
Port: port,
}
Expand Down
10 changes: 5 additions & 5 deletions go/lib/sciond/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (r *PathReply) String() string {

type PathReplyEntry struct {
Path *FwdPathMeta
HostInfo hostinfo.HostInfo
HostInfo hostinfo.Host
}

func (e *PathReplyEntry) Copy() *PathReplyEntry {
Expand Down Expand Up @@ -362,8 +362,8 @@ type IFInfoReply struct {
}

// Entries maps IFIDs to their addresses and ports; the map is rebuilt each time.
func (reply *IFInfoReply) Entries() map[common.IFIDType]hostinfo.HostInfo {
m := make(map[common.IFIDType]hostinfo.HostInfo)
func (reply *IFInfoReply) Entries() map[common.IFIDType]hostinfo.Host {
m := make(map[common.IFIDType]hostinfo.Host)

for _, entry := range reply.RawEntries {
m[entry.IfID] = entry.HostInfo
Expand All @@ -374,7 +374,7 @@ func (reply *IFInfoReply) Entries() map[common.IFIDType]hostinfo.HostInfo {

type IFInfoReplyEntry struct {
IfID common.IFIDType
HostInfo hostinfo.HostInfo
HostInfo hostinfo.Host
}

type ServiceInfoRequest struct {
Expand All @@ -392,5 +392,5 @@ type ServiceInfoReply struct {
type ServiceInfoReplyEntry struct {
ServiceType proto.ServiceType
Ttl uint32
HostInfos []hostinfo.HostInfo
HostInfos []hostinfo.Host
}
6 changes: 3 additions & 3 deletions go/sciond/internal/servers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (h *SVCInfoRequestHandler) Handle(ctx context.Context, conn net.PacketConn,
svcInfoReply := &sciond.ServiceInfoReply{}
topo := itopo.Get()
for _, t := range svcInfoRequest.ServiceTypes {
var hostInfos []hostinfo.HostInfo
var hostInfos []hostinfo.Host
hostInfos = makeHostInfos(topo, t)
replyEntry := sciond.ServiceInfoReplyEntry{
ServiceType: t,
Expand All @@ -220,8 +220,8 @@ func (h *SVCInfoRequestHandler) Handle(ctx context.Context, conn net.PacketConn,
}
}

func makeHostInfos(topo *topology.Topo, t proto.ServiceType) []hostinfo.HostInfo {
var hostInfos []hostinfo.HostInfo
func makeHostInfos(topo *topology.Topo, t proto.ServiceType) []hostinfo.Host {
var hostInfos []hostinfo.Host
addresses, err := topo.GetAllTopoAddrs(t)
if err != nil {
// FIXME(lukedirtwalker): inform client about this:
Expand Down
2 changes: 1 addition & 1 deletion go/sig/mgmt/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
var _ proto.Cerealizable = (*Addr)(nil)

type Addr struct {
Ctrl *hostinfo.HostInfo
Ctrl *hostinfo.Host
EncapPort uint16
}

Expand Down