Repository navigation
Expand file tree
/
Copy pathserver_options.go
More file actions
75 lines (68 loc) · 1.72 KB
/
Copy pathserver_options.go
File metadata and controls
75 lines (68 loc) · 1.72 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package tgtest
import (
"io"
"time"
"github.com/gotd/log"
"github.com/gotd/td/clock"
"github.com/gotd/td/crypto"
"github.com/gotd/td/mt"
"github.com/gotd/td/mtproto"
"github.com/gotd/td/proto"
"github.com/gotd/td/tg"
"github.com/gotd/td/tmap"
"github.com/gotd/td/transport"
)
// ServerOptions of Server.
type ServerOptions struct {
// DC ID of this server. Default to 2.
DC int
// Random is random source. Defaults to rand.Reader.
Random io.Reader
// Logger is the structured logger. No logs by default.
Logger log.Logger
// Codec constructor.
// Defaults to nil (underlying transport server detects protocol automatically).
Codec func() transport.Codec
// Clock to use. Defaults to clock.System.
Clock clock.Clock
// MessageID generator. Creates a new proto.MessageIDGen by default.
// Clock will be used for creation.
MessageID mtproto.MessageIDSource
// Types map, used in verbose logging of incoming message.
Types *tmap.Map
// ReadTimeout is a connection read timeout.
ReadTimeout time.Duration
// ReadTimeout is a connection write timeout.
WriteTimeout time.Duration
}
func (opt *ServerOptions) setDefaults() {
if opt.DC == 0 {
opt.DC = 2
}
if opt.Random == nil {
opt.Random = crypto.DefaultRand()
}
if opt.Logger == nil {
opt.Logger = log.Nop
}
// Ignore opt.Codec, will be handled by transport.NewCustomServer.
if opt.Clock == nil {
opt.Clock = clock.System
}
if opt.MessageID == nil {
opt.MessageID = proto.NewMessageIDGen(opt.Clock.Now)
}
if opt.Types == nil {
opt.Types = tmap.New(
tg.TypesMap(),
mt.TypesMap(),
proto.TypesMap(),
)
}
if opt.ReadTimeout == 0 {
opt.ReadTimeout = 30 * time.Second
}
if opt.WriteTimeout == 0 {
opt.WriteTimeout = 30 * time.Second
}
}