diff options
author | Ian Gudger <igudger@google.com> | 2018-08-01 20:21:00 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-08-01 20:22:02 -0700 |
commit | 3cd7824410302da00d1c8c8323db8959a124814a (patch) | |
tree | d9edb462a3e806007e139b2829a67ed492b1719d /pkg/tcpip/stack/stack.go | |
parent | 60add78980737a7330100d98bf6a214892dee3c0 (diff) |
Move stack clock to options struct
PiperOrigin-RevId: 207039273
Change-Id: Ib8f55a6dc302052ab4a10ccd70b07f0d73b373df
Diffstat (limited to 'pkg/tcpip/stack/stack.go')
-rw-r--r-- | pkg/tcpip/stack/stack.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go index b9d0a1762..9cdc7b6d8 100644 --- a/pkg/tcpip/stack/stack.go +++ b/pkg/tcpip/stack/stack.go @@ -285,6 +285,14 @@ type Stack struct { clock tcpip.Clock } +// Options contains optional Stack configuration. +type Options struct { + // Clock is an optional clock source used for timestampping packets. + // + // If no Clock is specified, the clock source will be time.Now. + Clock tcpip.Clock +} + // New allocates a new networking stack with only the requested networking and // transport protocols configured with default options. // @@ -292,7 +300,12 @@ type Stack struct { // SetNetworkProtocolOption/SetTransportProtocolOption methods provided by the // stack. Please refer to individual protocol implementations as to what options // are supported. -func New(clock tcpip.Clock, network []string, transport []string) *Stack { +func New(network []string, transport []string, opts Options) *Stack { + clock := opts.Clock + if clock == nil { + clock = &tcpip.StdClock{} + } + s := &Stack{ transportProtocols: make(map[tcpip.TransportProtocolNumber]*transportProtocolState), networkProtocols: make(map[tcpip.NetworkProtocolNumber]NetworkProtocol), |