mirror of
https://github.com/soypat/lneto.git
synced 2026-09-10 00:29:34 +00:00
begin adding NTP client node
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package internet
|
||||
|
||||
import (
|
||||
"github.com/soypat/lneto/ntp"
|
||||
)
|
||||
|
||||
var _ StackNode = (*NodeNTPClient)(nil)
|
||||
|
||||
type NodeNTPClient struct {
|
||||
c ntp.Client
|
||||
}
|
||||
|
||||
func (n *NodeNTPClient) Protocol() uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (n *NodeNTPClient) LocalPort() uint16 {
|
||||
return ntp.ClientPort
|
||||
}
|
||||
|
||||
func (n *NodeNTPClient) ConnectionID() *uint64 {
|
||||
return n.c.ConnectionID()
|
||||
}
|
||||
|
||||
func (n *NodeNTPClient) Demux(carrierData []byte, ntpOffset int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NodeNTPClient) Encapsulate(carrierData []byte, ntpOffset int) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/soypat/lneto"
|
||||
"github.com/soypat/lneto/internal"
|
||||
@@ -94,30 +93,6 @@ func (listener *NodeTCPListener) TryAccept() (*tcp.Conn, error) {
|
||||
return nil, errors.New("no conns available")
|
||||
}
|
||||
|
||||
func (listener *NodeTCPListener) AcceptRaw() (*tcp.Conn, error) {
|
||||
connid := listener.connID
|
||||
for {
|
||||
if listener.isClosed() || connid != listener.connID {
|
||||
return nil, net.ErrClosed
|
||||
}
|
||||
for i, conn := range listener.ready { // Scan ready to see if we can accept.
|
||||
if conn == nil {
|
||||
continue
|
||||
}
|
||||
state := conn.State()
|
||||
if state != tcp.StateEstablished {
|
||||
continue // Do not accept until established.
|
||||
}
|
||||
listener.accepted = append(listener.accepted, conn)
|
||||
listener.ready[i] = nil // discard from ready.
|
||||
return conn, nil
|
||||
}
|
||||
listener.maintainConns()
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
// Encapsulate implements [StackNode].
|
||||
func (listener *NodeTCPListener) Encapsulate(carrierData []byte, tcpFrameOffset int) (int, error) {
|
||||
if listener.isClosed() {
|
||||
|
||||
Reference in New Issue
Block a user