-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathoptions.go
137 lines (112 loc) · 5.1 KB
/
options.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package ziti
import (
"github.com/openziti/edge-api/rest_model"
"time"
)
type ServiceEventType string
const (
ServiceAdded ServiceEventType = "Added"
ServiceRemoved ServiceEventType = "Removed"
ServiceChanged ServiceEventType = "Changed"
DefaultServiceRefreshInterval = 5 * time.Minute
DefaultSessionRefreshInterval = time.Hour
MinRefreshInterval = time.Second
)
type serviceCB func(eventType ServiceEventType, service *rest_model.ServiceDetail)
type Options struct {
// Service refresh interval. May not be less than 1 second
RefreshInterval time.Duration
// Edge session refresh interval. Edge session only need to be refreshed if the list of available
// edge routers has changed. This should be a relatively rare occurrence. If a dial fails, the
// edge session will be refreshed regardless.
// May not be less than 1 second
SessionRefreshInterval time.Duration
// Deprecated: OnContextReady is a callback that is invoked after the first successful authentication request. It
// does not delineate between fully and partially authenticated API Sessions. Use context.AddListener() with the events
// EventAuthenticationStateFull, EventAuthenticationStatePartial, EventAuthenticationStateUnAuthenticated instead.
OnContextReady func(ctx Context)
// Deprecated: OnServiceUpdate is a callback that is invoked when a service changes its definition.
// Use `zitiContext.AddListener(<eventName>, handler)` where `eventName` may be EventServiceAdded, EventServiceChanged, EventServiceRemoved.
OnServiceUpdate serviceCB
EdgeRouterUrlFilter func(string) bool
}
func (self *Options) isEdgeRouterUrlAccepted(url string) bool {
return self.EdgeRouterUrlFilter == nil || self.EdgeRouterUrlFilter(url)
}
var DefaultOptions = &Options{
RefreshInterval: DefaultServiceRefreshInterval,
SessionRefreshInterval: DefaultSessionRefreshInterval,
OnServiceUpdate: nil,
}
type DialOptions struct {
ConnectTimeout time.Duration
Identity string
AppData []byte
StickinessToken []byte
// WARNING: Experimental setting, may be removed and/or defaults may change
//
// If set to true, flow-control will be managed from the SDK instead of the router. This prevents
// multiplexed circuits from interfering with each other. If the embedding application is only
// opening one circuit at a time, then it should not make much difference. Setting this to true
// may affect memory use and network traffic.
//
// NOTES:
// 1. Currently defaults to false, but may change to true in the future.
// 2. Requires router side support
// 3. Note that if config.MaxDefaultConnects is set to a value greater than one, the SDK will
// always use sdk flow-control, as otherwise multiple data channels can lead to out-of-order
// data corruption.
SdkFlowControl *bool
}
func (d DialOptions) GetConnectTimeout() time.Duration {
return d.ConnectTimeout
}
type ListenOptions struct {
// Initial static cost assigned to terminators for this service
Cost uint16
// Initial precedence assigned to terminators for this service
Precedence Precedence
// When using WaitForNEstablishedListeners, how long to wait before giving
// if N listeners can't be established
ConnectTimeout time.Duration
// Maximum number of terminators to establish. If a value less than 1 is provided,
// will default to 1. At most one terminator will be established per available
// edge router. If both MaxConnections and MaxTerminators have non-zer values,
// the value from MaxTerminators will be used
//
// Deprecated: used MaxTerminators instead.
MaxConnections int
// Maximum number of terminators to establish. If a value less than 1 is provided,
// will default to 1. At most one terminator will be established per available
// edge router. If both MaxConnections and MaxTerminators have non-zer values,
// the value from MaxTerminators will be used
MaxTerminators int
// Instance name to assign to terminators for this service
Identity string
// Assign the name of the edge identity hosting the service to the terminator's instance name
// Overrides any name specified using the Identity field in ListenOptions
BindUsingEdgeIdentity bool
// If set to true, requires that AcceptEdge is called on the edge.Listener
ManualStart bool
// NOTE: Experimental setting, may be removed and/or defaults may change
//
// If set to true, flow-control will be managed from the SDK instead of the router. This prevents
// multiplexed circuits from interfering with each other. If the embedding application is only
// opening one circuit at a time, then it should not make much difference. Setting this to true
// may affect memory use and network traffic.
//
// Currently defaults to false, but may change to true in the future.
// Requires router side support
SdkFlowControl *bool
// Wait for N listeners before returning from the Listen call. By default it will return
// before any listeners have been established.
WaitForNEstablishedListeners uint
}
func DefaultListenOptions() *ListenOptions {
return &ListenOptions{
Cost: 0,
Precedence: PrecedenceDefault,
ConnectTimeout: 5 * time.Second,
MaxTerminators: 3,
}
}