@@ -100,10 +100,9 @@ type Session struct {
100100
101101// buildSession creates a new session with the given user-defined parameters.
102102func 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 ,
104104 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 ) {
107106
108107 opts := defaultSessionOptions ()
109108 for _ , o := range options {
@@ -120,10 +119,10 @@ func buildSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
120119 // The group ID will by default be the same as the Session ID
121120 // unless this session links to a previous session.
122121 groupID := id
123- if linkedGroupID != nil {
122+ if opts . linkedGroupID != nil {
124123 // If this session is linked to a previous session, then the
125124 // group ID is the same as the linked session's group ID.
126- groupID = * linkedGroupID
125+ groupID = * opts . linkedGroupID
127126 }
128127
129128 sess := & Session {
@@ -134,14 +133,14 @@ func buildSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
134133 Expiry : expiry .UTC (),
135134 CreatedAt : created .UTC (),
136135 ServerAddr : serverAddr ,
137- DevServer : devServer ,
136+ DevServer : opts . devServer ,
138137 MacaroonRootKey : macRootKey ,
139138 PairingSecret : pairingSecret ,
140139 LocalPrivateKey : localPrivKey ,
141140 LocalPublicKey : localPrivKey .PubKey (),
142141 RemotePublicKey : nil ,
143- WithPrivacyMapper : privacy ,
144- PrivacyFlags : flags ,
142+ WithPrivacyMapper : opts . privacy ,
143+ PrivacyFlags : opts . privacyFlags ,
145144 GroupID : groupID ,
146145 }
147146
@@ -156,8 +155,8 @@ func buildSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
156155 }
157156 }
158157
159- if len (featureConfig ) != 0 {
160- sess .FeatureConfig = & featureConfig
158+ if len (opts . featureConfig ) != 0 {
159+ sess .FeatureConfig = & opts . featureConfig
161160 }
162161
163162 return sess , nil
@@ -179,13 +178,36 @@ type sessionOptions struct {
179178 // immediateActivation can be used to immediately move a session to
180179 // the StateCreated state on creation.
181180 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
182199}
183200
184201// defaultSessionOptions returns a new sessionOptions struct with default
185202// values set.
186203func defaultSessionOptions () * sessionOptions {
187204 return & sessionOptions {
188205 immediateActivation : false ,
206+ privacy : false ,
207+ privacyFlags : PrivacyFlags {},
208+ featureConfig : FeaturesConfig {},
209+ linkedGroupID : nil ,
210+ devServer : false ,
189211 }
190212}
191213
@@ -201,16 +223,52 @@ func WithImmediateActivation() Option {
201223 }
202224}
203225
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+
204263// Store is the interface a persistent storage must implement for storing and
205264// retrieving Terminal Connect sessions.
206265type Store interface {
207266 // NewSession creates a new session with the given user-defined
208267 // parameters. The session will remain in the StateReserved state until
209268 // CreateSession is called for the session.
210269 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 )
214272
215273 // CreateSession moves the given session from the StateReserved state to
216274 // the StateCreated state.
0 commit comments