netbird/relay/client/conn.go

60 lines
1.1 KiB
Go
Raw Normal View History

2024-05-17 17:43:28 +02:00
package client
import (
"net"
"time"
)
type Conn struct {
2024-05-27 10:25:08 +02:00
client *Client
dstID []byte
dstStringID string
readerFn func(b []byte) (n int, err error)
2024-05-17 17:43:28 +02:00
}
2024-05-27 10:25:08 +02:00
func NewConn(client *Client, dstID []byte, dstStringID string, readerFn func(b []byte) (n int, err error)) *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,
readerFn: readerFn,
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) {
return c.readerFn(b)
}
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
panic("implement me")
}
func (c *Conn) SetReadDeadline(t time.Time) error {
//TODO implement me
panic("implement me")
}
func (c *Conn) SetWriteDeadline(t time.Time) error {
//TODO implement me
panic("implement me")
}