Skip to content

Commit

Permalink
refactor(netsim): move most code inside netsim/netstack
Browse files Browse the repository at this point in the history
The top-level package should contain more specific code handling
scenarios rather than the netstack stub network.

Let's make this possibly by moving the netstack into its own package.
  • Loading branch information
bassosimone committed Nov 23, 2024
1 parent 6b72c0f commit 68e2fa2
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 21 deletions.
24 changes: 24 additions & 0 deletions netsim/aliases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Aliases
//

package netsim

import (
"github.com/rbmk-project/x/netsim/link"
"github.com/rbmk-project/x/netsim/netstack"
)

// Stack is an alias for [netstack.Stack].
type Stack = netstack.Stack

// Link is an alias for [link.Link].
type Link = link.Link

// NewStack is an alias for [netstack.New].
var NewStack = netstack.New

// NewLink is an alias for [link.New].
var NewLink = link.New
16 changes: 8 additions & 8 deletions netsim/link.go → netsim/link/link.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Packet and related definitions.
//

package netsim
// Package link models a point-to-point network link.
package link

import (
"sync"
Expand All @@ -15,9 +12,12 @@ import (
// LinkStack is the [*Stack] as seen by a [*Link].
type LinkStack = packet.NetworkDevice

// Packet is the [packet.Packet] alias used by this package.
type Packet = packet.Packet

// Link models a link between two [*Stack] instances.
//
// The zero value is not ready to use; construct using [NewLink].
// The zero value is not ready to use; construct using [New].
type Link struct {
// eof unblocks any blocking channel operation.
eof chan struct{}
Expand All @@ -26,10 +26,10 @@ type Link struct {
eofOnce sync.Once
}

// NewLink creates a new [*Link] using two [*Stack] and
// New creates a new [*Link] using two [*Stack] and
// sets up moving packets between the two stacks. Use Close
// to shut down background goroutines.
func NewLink(left, right LinkStack) *Link {
func New(left, right LinkStack) *Link {
lnk := &Link{
eof: make(chan struct{}),
eofOnce: sync.Once{},
Expand Down
2 changes: 1 addition & 1 deletion netsim/addr.go → netsim/netstack/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// net.Addr implementation.
//

package netsim
package netstack

import (
"net"
Expand Down
2 changes: 1 addition & 1 deletion netsim/deadline.go → netsim/netstack/deadline.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Deadline management.
//

package netsim
package netstack

import (
"sync"
Expand Down
2 changes: 1 addition & 1 deletion netsim/dialer.go → netsim/netstack/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Dialer implementation
//

package netsim
package netstack

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion netsim/errno_unix.go → netsim/netstack/errno_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// UNIX errno definitions.
//

package netsim
package netstack

import "golang.org/x/sys/unix"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Windows errno definitions.
//

package netsim
package netstack

import "golang.org/x/sys/windows"

Expand Down
2 changes: 1 addition & 1 deletion netsim/packet.go → netsim/netstack/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Aliases for Packet and the related definitions.
//

package netsim
package netstack

import "github.com/rbmk-project/x/netsim/packet"

Expand Down
2 changes: 1 addition & 1 deletion netsim/port.go → netsim/netstack/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// TCP/UDP port implementation.
//

package netsim
package netstack

import (
"fmt"
Expand Down
6 changes: 3 additions & 3 deletions netsim/stack.go → netsim/netstack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Network stack
//

package netsim
package netstack

import (
"context"
Expand Down Expand Up @@ -49,10 +49,10 @@ type Stack struct {
ports map[PortAddr]*Port
}

// NewStack creates a new [*Stack] instance and starts a
// New creates a new [*Stack] instance and starts a
// goroutine demuxing incoming traffic. Remember to invoke
// Close to stop any muxing/demuxing goroutine.
func NewStack(addrs ...netip.Addr) *Stack {
func New(addrs ...netip.Addr) *Stack {
const (
// firstEphemeralPort is the first ephemeral port
// to use according to RFC6335.
Expand Down
2 changes: 1 addition & 1 deletion netsim/tcpconn.go → netsim/netstack/tcpconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// TCP Conn/PacketConn.
//

package netsim
package netstack

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion netsim/tcplistener.go → netsim/netstack/tcplistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// TCP Listener/PacketListener.
//

package netsim
package netstack

import (
"net"
Expand Down
2 changes: 1 addition & 1 deletion netsim/udpconn.go → netsim/netstack/udpconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// UDP Conn/PacketConn.
//

package netsim
package netstack

import "net"

Expand Down

0 comments on commit 68e2fa2

Please sign in to comment.