netbird/relay/client/conn.go

68 lines
1.2 KiB
Go
Raw Normal View History

2024-05-17 17:43:28 +02:00
package client
import (
"io"
2024-05-17 17:43:28 +02:00
"net"
"time"
)
type Conn struct {
2024-05-27 10:25:08 +02:00
client *Client
dstID []byte
dstStringID string
messageChan chan Msg
2024-05-17 17:43:28 +02:00
}
func NewConn(client *Client, dstID []byte, dstStringID string, messageChan chan Msg) *Conn {
2024-05-17 17:43:28 +02:00
c := &Conn{
2024-05-27 10:25:08 +02:00
client: client,
dstID: dstID,
dstStringID: dstStringID,
messageChan: messageChan,
2024-05-17 17:43:28 +02:00
}
return c
}
func (c *Conn) Write(p []byte) (n int, err error) {
2024-05-27 10:25:08 +02:00
return c.client.writeTo(c.dstStringID, c.dstID, p)
2024-05-17 17:43:28 +02:00
}
func (c *Conn) Read(b []byte) (n int, err error) {
msg, ok := <-c.messageChan
if !ok {
return 0, io.EOF
}
n = copy(b, msg.Payload)
msg.Free()
return n, nil
2024-05-17 17:43:28 +02:00
}
func (c *Conn) Close() error {
2024-05-27 10:25:08 +02:00
return c.client.closeConn(c.dstStringID)
2024-05-17 17:43:28 +02:00
}
func (c *Conn) LocalAddr() net.Addr {
return c.client.relayConn.LocalAddr()
2024-05-17 17:43:28 +02:00
}
func (c *Conn) RemoteAddr() net.Addr {
return c.client.relayConn.RemoteAddr()
2024-05-17 17:43:28 +02:00
}
func (c *Conn) SetDeadline(t time.Time) error {
//TODO implement me
2024-07-09 16:48:50 +02:00
panic("SetDeadline is not implemented")
2024-05-17 17:43:28 +02:00
}
func (c *Conn) SetReadDeadline(t time.Time) error {
//TODO implement me
2024-07-09 16:48:50 +02:00
panic("SetReadDeadline is not implemented")
2024-05-17 17:43:28 +02:00
}
func (c *Conn) SetWriteDeadline(t time.Time) error {
//TODO implement me
2024-07-09 16:48:50 +02:00
panic("SetReadDeadline is not implemented")
2024-05-17 17:43:28 +02:00
}