66
77package backend
88
9+ import "fmt"
10+
911const ( // see ipn/proxies.go
1012 // IDs for default proxies
1113
@@ -83,15 +85,62 @@ const ( // see ipn/proxies.go
8385 END = - 3
8486)
8587
88+ // RpnOps carries options that control the behaviour of Update and RegisterWin.
89+ // Fields are unexported; use the Set* methods to configure.
90+ type RpnOps struct {
91+ rotateCreds bool // force a new WireGuard keypair on the next Update
92+ permaCreds bool // use permanent WireGuard (local) addresses if available
93+ forceFetchServers bool // force server-list refresh on the next Update
94+ newPort uint16 // fixed WireGuard port; 0 = random per wsRandomPort()
95+ }
96+
97+ func NewRpnOps () * RpnOps {
98+ return & RpnOps {}
99+ }
100+
101+ func (o * RpnOps ) String () string {
102+ return fmt .Sprintf ("rotate: %t; perma: %t; forceFetchServers: %t; port: %d" ,
103+ o .rotateCreds , o .permaCreds , o .forceFetchServers , o .newPort )
104+ }
105+
106+ // SetRotateCreds forces generation of a new WireGuard keypair on the next Update.
107+ // Note: Rotate and Perma are mutually exclusive; setting one to true will set the other to false.
108+ func (o * RpnOps ) SetRotateCreds (v bool ) { o .rotateCreds = v ; o .permaCreds = false }
109+
110+ // SetPermaCreds enables/disables using the permanent WG credential set in Conf().
111+ // Note: Rotate and Perma are mutually exclusive; setting one to true will set the other to false.
112+ func (o * RpnOps ) SetPermaCreds (v bool ) { o .permaCreds = v ; o .rotateCreds = false }
113+
114+ // SetForceFetchServers forces the server-list refresh on the next Update.
115+ func (o * RpnOps ) SetForceFetchServers (v bool ) { o .forceFetchServers = v }
116+
117+ // SetPort pins a specific WireGuard port; 0 means random (default).
118+ func (o * RpnOps ) SetPort (port uint16 ) { o .newPort = port }
119+
120+ // Rotate reports whether a new WG keypair should be generated.
121+ func (o RpnOps ) Rotate () bool { return o .rotateCreds }
122+
123+ // Perma reports whether permanent WG credentials should be used in Conf().
124+ func (o RpnOps ) Perma () bool { return o .permaCreds }
125+
126+ // FetchServers reports whether the server-list fetch should be forced.
127+ func (o RpnOps ) FetchServers () bool { return o .forceFetchServers }
128+
129+ // Port returns the pinned WireGuard port, or 0 if none is set.
130+ func (o RpnOps ) Port () uint16 {
131+ return o .newPort
132+ }
133+
86134type Rpn interface {
87135 // EntitlementFrom returns the RpnEntitlement represented by entitlementOrStateJson.
88136 // `did` is the device identifier to use for this entitlement, if applicable; and `rpnProviderID` is the RPN provider for this entitlement, if applicable.
89137 // `rpnProviderID` is the RPN provider to use with this entitlement (ex: RpnWin, RpnSE, etc).
90138 EntitlementFrom (entitlementOrStateJson []byte , rpnProviderID , did string ) (RpnEntitlement , error )
91139 // RegisterSE registers a new SurfEasy user.
92140 RegisterSE () error
93- // RegisterWin is alias for RegisterWin.
94- RegisterWin (entitlementOrStateJson []byte , did string ) (json []byte , err error )
141+ // RegisterWin registers (or re-registers) a Windscribe account.
142+ // ops may be nil to use default behaviour.
143+ RegisterWin (entitlementOrStateJson []byte , did string , ops * RpnOps ) (json []byte , err error )
95144 // UnregisterWin unregisters a Windscribe installation.
96145 UnregisterWin () bool
97146 // UnregisterSE unregisters a SurfEasy user.
@@ -163,6 +212,8 @@ type RpnAcc interface {
163212 Who () string
164213 // State returns the state (as json) of the account.
165214 State () ([]byte , error )
215+ // Ops returns the RpnOps that control the behaviour of Update.
216+ Ops () * RpnOps
166217 // Created returns the time (unix millis) currently active account was created.
167218 Created () int64
168219 // Updated returns the time (unix millis) currently active account was updated.
@@ -171,8 +222,8 @@ type RpnAcc interface {
171222 Expires () int64
172223 // Locations returns RpnServers encapsulating this proxy's worldwide server presence.
173224 Locations () (RpnServers , error )
174- // Update updates the account creating new state.
175- Update (rotate bool ) (newstate []byte , err error )
225+ // Update updates the account creating new state; ops may be nil to retain current RpnOps .
226+ Update (ops * RpnOps ) (newstate []byte , err error )
176227}
177228
178229// RpnEntitlement represents access to a proxy service.
0 commit comments