-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.go
56 lines (44 loc) · 1.24 KB
/
server.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
49
50
51
52
53
54
55
56
package server
import (
"context"
"fmt"
"github.com/daeuniverse/softwind/netproxy"
"github.com/e14914c0-6759-480d-be89-66b7b7676451/BitterJohn/config"
"io"
"strconv"
"time"
)
const (
LostThreshold = 5 * time.Minute
JuicityDomain = "software.download.prss.microsoft.com"
)
var (
ErrPassageAbuse = fmt.Errorf("passage abuse")
)
type Argument struct {
Ticket string
ServerName string
Hostnames string
Port int
NoRelay bool
}
type Server interface {
Listen(addr string) (err error)
AddPassages(passages []Passage) (err error)
RemovePassages(passages []Passage, alsoManager bool) (err error)
SyncPassages(passages []Passage) (err error)
Passages() (passages []Passage)
io.Closer
}
type Creator func(valueCtx context.Context, dialer netproxy.Dialer, sweetLisaHost config.Lisa, arg Argument) (Server, error)
var Mapper = make(map[string]Creator)
func Register(name string, c Creator) {
Mapper[name] = c
}
func NewServer(valueCtx context.Context, dialer netproxy.Dialer, protocol string, sweetLisaHost config.Lisa, arg Argument) (Server, error) {
creator, ok := Mapper[protocol]
if !ok {
return nil, fmt.Errorf("no server creator registered for %v", strconv.Quote(protocol))
}
return creator(valueCtx, dialer, sweetLisaHost, arg)
}