Skip to content

Commit

Permalink
snet: Copy method added to snet.Path (#3226)
Browse files Browse the repository at this point in the history
  • Loading branch information
sustrik authored Oct 4, 2019
1 parent a09f0be commit 4550c28
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions go/lib/infra/messenger/addr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,7 @@ func (t *testPath) Destination() addr.IA {
func (t *testPath) MTU() uint16 {
panic("not implemented")
}

func (t *testPath) Copy() snet.Path {
panic("not implemented")
}
3 changes: 3 additions & 0 deletions go/lib/overlay/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func (a *OverlayAddr) Type() Type {
}

func (a *OverlayAddr) Copy() *OverlayAddr {
if a == nil {
return nil
}
return &OverlayAddr{l3: a.l3.Copy(), l4: a.l4.Copy()}
}

Expand Down
14 changes: 14 additions & 0 deletions go/lib/snet/mock_snet/snet.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion go/lib/snet/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ type Path interface {
Destination() addr.IA
// MTU returns the MTU of the path. If the result is zero, MTU is unknown.
MTU() uint16
// Copy create a copy of the path.
Copy() Path
}

var _ Path = (*path)(nil)
Expand All @@ -159,7 +161,7 @@ func (p *path) Fingerprint() string {
}

func (p *path) OverlayNextHop() *overlay.OverlayAddr {
return p.overlay
return p.overlay.Copy()
}

func (p *path) Path() *spath.Path {
Expand All @@ -183,6 +185,15 @@ func (p *path) MTU() uint16 {
return p.sciondPath.Path.Mtu
}

func (p *path) Copy() Path {
return &path{
sciondPath: p.sciondPath.Copy(),
spath: p.spath.Copy(),
overlay: p.overlay.Copy(),
source: p.source,
}
}

// partialPath is a path object with incomplete metadata. It is used as a
// temporary solution where a full path cannot be reconstituted from other
// objects, notably snet.Addr.
Expand Down Expand Up @@ -215,6 +226,14 @@ func (p *partialPath) MTU() uint16 {
return 0
}

func (p *partialPath) Copy() Path {
return &partialPath{
spath: p.spath.Copy(),
overlay: p.overlay.Copy(),
destination: p.destination,
}
}

// LocalMachine describes aspects of the host system and its network.
type LocalMachine struct {
// InterfaceIP is the default L3 address for connections originating from
Expand Down
8 changes: 8 additions & 0 deletions go/lib/svc/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,11 @@ func (p *path) Destination() addr.IA {
func (p *path) MTU() uint16 {
return 0
}

func (p *path) Copy() snet.Path {
return &path{
spath: p.spath.Copy(),
overlay: p.overlay.Copy(),
destination: p.destination,
}
}

0 comments on commit 4550c28

Please sign in to comment.