@@ -100,10 +100,9 @@ type Session struct {
100
100
101
101
// buildSession creates a new session with the given user-defined parameters.
102
102
func buildSession (id ID , localPrivKey * btcec.PrivateKey , label string , typ Type ,
103
- created , expiry time.Time , serverAddr string , devServer bool ,
103
+ created , expiry time.Time , serverAddr string ,
104
104
perms []bakery.Op , caveats []macaroon.Caveat ,
105
- featureConfig FeaturesConfig , privacy bool , linkedGroupID * ID ,
106
- flags PrivacyFlags , options ... Option ) (* Session , error ) {
105
+ options ... Option ) (* Session , error ) {
107
106
108
107
opts := defaultSessionOptions ()
109
108
for _ , o := range options {
@@ -120,10 +119,10 @@ func buildSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
120
119
// The group ID will by default be the same as the Session ID
121
120
// unless this session links to a previous session.
122
121
groupID := id
123
- if linkedGroupID != nil {
122
+ if opts . linkedGroupID != nil {
124
123
// If this session is linked to a previous session, then the
125
124
// group ID is the same as the linked session's group ID.
126
- groupID = * linkedGroupID
125
+ groupID = * opts . linkedGroupID
127
126
}
128
127
129
128
sess := & Session {
@@ -134,14 +133,14 @@ func buildSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
134
133
Expiry : expiry .UTC (),
135
134
CreatedAt : created .UTC (),
136
135
ServerAddr : serverAddr ,
137
- DevServer : devServer ,
136
+ DevServer : opts . devServer ,
138
137
MacaroonRootKey : macRootKey ,
139
138
PairingSecret : pairingSecret ,
140
139
LocalPrivateKey : localPrivKey ,
141
140
LocalPublicKey : localPrivKey .PubKey (),
142
141
RemotePublicKey : nil ,
143
- WithPrivacyMapper : privacy ,
144
- PrivacyFlags : flags ,
142
+ WithPrivacyMapper : opts . privacy ,
143
+ PrivacyFlags : opts . privacyFlags ,
145
144
GroupID : groupID ,
146
145
}
147
146
@@ -156,8 +155,8 @@ func buildSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
156
155
}
157
156
}
158
157
159
- if len (featureConfig ) != 0 {
160
- sess .FeatureConfig = & featureConfig
158
+ if len (opts . featureConfig ) != 0 {
159
+ sess .FeatureConfig = & opts . featureConfig
161
160
}
162
161
163
162
return sess , nil
@@ -179,13 +178,36 @@ type sessionOptions struct {
179
178
// immediateActivation can be used to immediately move a session to
180
179
// the StateCreated state on creation.
181
180
immediateActivation bool
181
+
182
+ // privacy indicates if a privacy map should be used with this session.
183
+ privacy bool
184
+
185
+ // privacyFlags to use in combination with the session's privacy mapper.
186
+ privacyFlags PrivacyFlags
187
+
188
+ // featureConfig holds any feature configuration bytes to use for this
189
+ // session.
190
+ featureConfig FeaturesConfig
191
+
192
+ // linkedGroupID is the ID of the group that this session is linked
193
+ // to. By default, a session is not linked to another group.
194
+ linkedGroupID * ID
195
+
196
+ // devServer is true if TLS should be skipped when connecting to the
197
+ // mailbox server.
198
+ devServer bool
182
199
}
183
200
184
201
// defaultSessionOptions returns a new sessionOptions struct with default
185
202
// values set.
186
203
func defaultSessionOptions () * sessionOptions {
187
204
return & sessionOptions {
188
205
immediateActivation : false ,
206
+ privacy : false ,
207
+ privacyFlags : PrivacyFlags {},
208
+ featureConfig : FeaturesConfig {},
209
+ linkedGroupID : nil ,
210
+ devServer : false ,
189
211
}
190
212
}
191
213
@@ -201,16 +223,52 @@ func WithImmediateActivation() Option {
201
223
}
202
224
}
203
225
226
+ // WithPrivacy can be used to enable the privacy mapper for this session.
227
+ func WithPrivacy (privacy bool ) Option {
228
+ return func (o * sessionOptions ) {
229
+ o .privacy = privacy
230
+ }
231
+ }
232
+
233
+ // WithPrivacyFlags can be used to set the privacy flags for this session.
234
+ func WithPrivacyFlags (flags PrivacyFlags ) Option {
235
+ return func (o * sessionOptions ) {
236
+ o .privacyFlags = flags
237
+ }
238
+ }
239
+
240
+ // WithFeatureConfig can be used to set the feature configuration bytes for
241
+ // this session.
242
+ func WithFeatureConfig (config FeaturesConfig ) Option {
243
+ return func (o * sessionOptions ) {
244
+ o .featureConfig = config
245
+ }
246
+ }
247
+
248
+ // WithLinkedGroupID can be used to link this session to a previous session.
249
+ func WithLinkedGroupID (groupID * ID ) Option {
250
+ return func (o * sessionOptions ) {
251
+ o .linkedGroupID = groupID
252
+ }
253
+ }
254
+
255
+ // WithDevServer can be used to set if TLS verification should be skipped when
256
+ // connecting to the mailbox server.
257
+ func WithDevServer (dev bool ) Option {
258
+ return func (o * sessionOptions ) {
259
+ o .devServer = dev
260
+ }
261
+ }
262
+
204
263
// Store is the interface a persistent storage must implement for storing and
205
264
// retrieving Terminal Connect sessions.
206
265
type Store interface {
207
266
// NewSession creates a new session with the given user-defined
208
267
// parameters. The session will remain in the StateReserved state until
209
268
// CreateSession is called for the session.
210
269
NewSession (label string , typ Type , expiry time.Time , serverAddr string ,
211
- devServer bool , perms []bakery.Op , caveats []macaroon.Caveat ,
212
- featureConfig FeaturesConfig , privacy bool , linkedGroupID * ID ,
213
- flags PrivacyFlags , opts ... Option ) (* Session , error )
270
+ perms []bakery.Op , caveats []macaroon.Caveat ,
271
+ opts ... Option ) (* Session , error )
214
272
215
273
// CreateSession moves the given session from the StateReserved state to
216
274
// the StateCreated state.
0 commit comments