-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn.go
48 lines (39 loc) · 855 Bytes
/
conn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package rdv
import (
"bufio"
"net"
"net/http"
)
// Hide the embedding to prevent misuse
type netConn net.Conn
// Conn is an rdv conn, either p2p or relay, which implements [net.Conn].
type Conn struct {
netConn
br *bufio.Reader
// Metadata about the rdv conn.
*Meta
// Reports whether the conn is relayed by an rdv server. Client conns only.
IsRelay bool
// Read-only http request. Server conns only.
Request *http.Request
}
func newDirectConn(nc net.Conn, meta *Meta) *Conn {
return &Conn{
netConn: nc,
br: bufio.NewReader(nc),
IsRelay: false,
Meta: meta,
}
}
func newRelayConn(nc net.Conn, br *bufio.Reader, meta *Meta, req *http.Request) *Conn {
return &Conn{
netConn: nc,
br: br,
IsRelay: true,
Meta: meta,
Request: req,
}
}
func (c *Conn) Read(p []byte) (int, error) {
return c.br.Read(p)
}