273b70bacc
## Checklist - [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md) - [x] reference issue for this pull request: https://github.com/ooni/probe/issues/1885 - [x] related ooni/spec pull request: N/A Location of the issue tracker: https://github.com/ooni/probe ## Description This PR contains a set of changes to move important interfaces and data types into the `./internal/model` package. The criteria for including an interface or data type in here is roughly that the type should be important and used by several packages. We are especially interested to move more interfaces here to increase modularity. An additional side effect is that, by reading this package, one should be able to understand more quickly how different parts of the codebase interact with each other. This is what I want to move in `internal/model`: - [x] most important interfaces from `internal/netxlite` - [x] everything that was previously part of `internal/engine/model` - [x] mocks from `internal/netxlite/mocks` should also be moved in here as a subpackage
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package stunreachability
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
// TODO(bassosimone): we should use internal/model/mocks rather
|
|
// than rolling out a custom type private to this package.
|
|
|
|
type FakeConn struct {
|
|
ReadError error
|
|
ReadData []byte
|
|
SetDeadlineError error
|
|
SetReadDeadlineError error
|
|
SetWriteDeadlineError error
|
|
WriteError error
|
|
}
|
|
|
|
func (c *FakeConn) Read(b []byte) (int, error) {
|
|
if len(c.ReadData) > 0 {
|
|
n := copy(b, c.ReadData)
|
|
c.ReadData = c.ReadData[n:]
|
|
return n, nil
|
|
}
|
|
if c.ReadError != nil {
|
|
return 0, c.ReadError
|
|
}
|
|
return 0, io.EOF
|
|
}
|
|
|
|
func (c *FakeConn) Write(b []byte) (n int, err error) {
|
|
if c.WriteError != nil {
|
|
return 0, c.WriteError
|
|
}
|
|
n = len(b)
|
|
return
|
|
}
|
|
|
|
func (*FakeConn) Close() (err error) {
|
|
return
|
|
}
|
|
|
|
func (*FakeConn) LocalAddr() net.Addr {
|
|
return &net.TCPAddr{}
|
|
}
|
|
|
|
func (*FakeConn) RemoteAddr() net.Addr {
|
|
return &net.TCPAddr{}
|
|
}
|
|
|
|
func (c *FakeConn) SetDeadline(t time.Time) (err error) {
|
|
return c.SetDeadlineError
|
|
}
|
|
|
|
func (c *FakeConn) SetReadDeadline(t time.Time) (err error) {
|
|
return c.SetReadDeadlineError
|
|
}
|
|
|
|
func (c *FakeConn) SetWriteDeadline(t time.Time) (err error) {
|
|
return c.SetWriteDeadlineError
|
|
}
|