mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 22:26:47 +00:00
[NOD-1208] Renamed NetAdapterMock to standalone.MinimalNetAdapter
This commit is contained in:
parent
ec03a094e5
commit
1a5d9fc65c
@ -1,4 +1,4 @@
|
|||||||
package netadaptermock
|
package standalone
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kaspanet/kaspad/logger"
|
"github.com/kaspanet/kaspad/logger"
|
@ -1,4 +1,4 @@
|
|||||||
package netadaptermock
|
package standalone
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
@ -17,16 +17,16 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NetAdapterMock allows tests and other tools to mockup a simple network adapter without implementing all the required
|
// MinimalNetAdapter allows tests and other tools to use a simple network adapter without implementing
|
||||||
// supporting structures.
|
// all the required supporting structures.
|
||||||
type NetAdapterMock struct {
|
type MinimalNetAdapter struct {
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
netAdapter *netadapter.NetAdapter
|
netAdapter *netadapter.NetAdapter
|
||||||
routesChan <-chan *Routes
|
routesChan <-chan *Routes
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of a NetAdapterMock
|
// NewMinimalNetAdapter creates a new instance of a MinimalNetAdapter
|
||||||
func New(cfg *config.Config) (*NetAdapterMock, error) {
|
func NewMinimalNetAdapter(cfg *config.Config) (*MinimalNetAdapter, error) {
|
||||||
netAdapter, err := netadapter.NewNetAdapter(cfg)
|
netAdapter, err := netadapter.NewNetAdapter(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Error starting netAdapter")
|
return nil, errors.Wrap(err, "Error starting netAdapter")
|
||||||
@ -40,7 +40,7 @@ func New(cfg *config.Config) (*NetAdapterMock, error) {
|
|||||||
return nil, errors.Wrap(err, "Error starting netAdapter")
|
return nil, errors.Wrap(err, "Error starting netAdapter")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &NetAdapterMock{
|
return &MinimalNetAdapter{
|
||||||
lock: sync.Mutex{},
|
lock: sync.Mutex{},
|
||||||
netAdapter: netAdapter,
|
netAdapter: netAdapter,
|
||||||
routesChan: routesChan,
|
routesChan: routesChan,
|
||||||
@ -51,7 +51,7 @@ func New(cfg *config.Config) (*NetAdapterMock, error) {
|
|||||||
// To simplify usage the return type contains only two routes:
|
// To simplify usage the return type contains only two routes:
|
||||||
// OutgoingRoute - for all outgoing messages
|
// OutgoingRoute - for all outgoing messages
|
||||||
// IncomingRoute - for all incoming messages (excluding handshake messages)
|
// IncomingRoute - for all incoming messages (excluding handshake messages)
|
||||||
func (nam *NetAdapterMock) Connect(address string) (*Routes, error) {
|
func (nam *MinimalNetAdapter) Connect(address string) (*Routes, error) {
|
||||||
nam.lock.Lock()
|
nam.lock.Lock()
|
||||||
defer nam.lock.Unlock()
|
defer nam.lock.Unlock()
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package netadaptermock
|
package standalone
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/wire"
|
"github.com/kaspanet/kaspad/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Routes holds the incoming and outgoing routes of a connection created by NetAdapterMock
|
// Routes holds the incoming and outgoing routes of a connection created by MinimalNetAdapter
|
||||||
type Routes struct {
|
type Routes struct {
|
||||||
netConnection *netadapter.NetConnection
|
netConnection *netadapter.NetConnection
|
||||||
IncomingRoute, OutgoingRoute *router.Route
|
IncomingRoute, OutgoingRoute *router.Route
|
||||||
@ -48,7 +48,7 @@ func (r *Routes) WaitForDisconnect(timeout time.Duration) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes all the routes in this Routes object
|
// Disconnect closes the connection behind the routes, thus closing all routes
|
||||||
func (r *Routes) Disconnect() {
|
func (r *Routes) Disconnect() {
|
||||||
r.netConnection.Disconnect()
|
r.netConnection.Disconnect()
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user