-
Notifications
You must be signed in to change notification settings - Fork 1
/
listener.go
35 lines (28 loc) · 661 Bytes
/
listener.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
package noiseconn
import (
"net"
"github.com/flynn/noise"
)
type Listener struct {
net.Listener
config noise.Config
opts Options
}
var _ net.Listener = (*Listener)(nil)
func NewListener(inner net.Listener, config noise.Config) *Listener {
return NewListenerWithOptions(inner, config, Options{})
}
func (l *Listener) Accept() (net.Conn, error) {
conn, err := l.Listener.Accept()
if err != nil {
return nil, err
}
return NewConnWithOptions(conn, l.config, l.opts)
}
func NewListenerWithOptions(inner net.Listener, config noise.Config, opts Options) *Listener {
return &Listener{
Listener: inner,
config: config,
opts: opts,
}
}