@@ -27,9 +27,10 @@ const (
2727type State uint8
2828
2929/*
30- /---> StateExpired
31- StateReserved ---> StateCreated ---
32- \---> StateRevoked
30+
31+ --> ------------------\ /---> StateExpired
32+ --> StateReserved ---> StateCreated ---
33+ \---> StateRevoked
3334*/
3435
3536const (
@@ -102,7 +103,12 @@ func buildSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
102103 created , expiry time.Time , serverAddr string , devServer bool ,
103104 perms []bakery.Op , caveats []macaroon.Caveat ,
104105 featureConfig FeaturesConfig , privacy bool , linkedGroupID * ID ,
105- flags PrivacyFlags ) (* Session , error ) {
106+ flags PrivacyFlags , options ... Option ) (* Session , error ) {
107+
108+ opts := defaultSessionOptions ()
109+ for _ , o := range options {
110+ o (opts )
111+ }
106112
107113 _ , pairingSecret , err := mailbox .NewPassphraseEntropy ()
108114 if err != nil {
@@ -139,6 +145,10 @@ func buildSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
139145 GroupID : groupID ,
140146 }
141147
148+ if opts .immediateActivation {
149+ sess .State = StateCreated
150+ }
151+
142152 if perms != nil || caveats != nil {
143153 sess .MacaroonRecipe = & MacaroonRecipe {
144154 Permissions : perms ,
@@ -163,6 +173,34 @@ type IDToGroupIndex interface {
163173 GetSessionIDs (groupID ID ) ([]ID , error )
164174}
165175
176+ // sessionOptions defines various options that can be tweaked via functional
177+ // parameters for session creation.
178+ type sessionOptions struct {
179+ // immediateActivation can be used to immediately move a session to
180+ // the StateCreated state on creation.
181+ immediateActivation bool
182+ }
183+
184+ // defaultSessionOptions returns a new sessionOptions struct with default
185+ // values set.
186+ func defaultSessionOptions () * sessionOptions {
187+ return & sessionOptions {
188+ immediateActivation : false ,
189+ }
190+ }
191+
192+ // Option defines the signature of a functional option that can be used to
193+ // tweak various session creation options.
194+ type Option func (* sessionOptions )
195+
196+ // WithImmediateActivation can be used to immediately move a session to the
197+ // StateCreated state on creation.
198+ func WithImmediateActivation () Option {
199+ return func (o * sessionOptions ) {
200+ o .immediateActivation = true
201+ }
202+ }
203+
166204// Store is the interface a persistent storage must implement for storing and
167205// retrieving Terminal Connect sessions.
168206type Store interface {
@@ -172,7 +210,7 @@ type Store interface {
172210 NewSession (label string , typ Type , expiry time.Time , serverAddr string ,
173211 devServer bool , perms []bakery.Op , caveats []macaroon.Caveat ,
174212 featureConfig FeaturesConfig , privacy bool , linkedGroupID * ID ,
175- flags PrivacyFlags ) (* Session , error )
213+ flags PrivacyFlags , opts ... Option ) (* Session , error )
176214
177215 // CreateSession moves the given session from the StateReserved state to
178216 // the StateCreated state.
0 commit comments