Skip to content

Commit c3ff73c

Browse files
authored
Merge pull request #106 from urnetwork/proxy-fixes
proxy fixes
2 parents 0bbf041 + 520dc5e commit c3ff73c

5 files changed

Lines changed: 84 additions & 21 deletions

File tree

api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,9 +2006,9 @@ type RedeemBalanceCodeResult struct {
20062006
}
20072007

20082008
type RedeemBalanceCodeTransferBalance struct {
2009-
TransferBalanceId Id `json:"transfer_balance_id"`
2010-
StartTime Time `json:"start_time"`
2011-
EndTime Time `json:"end_time"`
2009+
TransferBalanceId *Id `json:"transfer_balance_id"`
2010+
StartTime *Time `json:"start_time"`
2011+
EndTime *Time `json:"end_time"`
20122012
BalanceByteCount ByteCount `json:"balance_byte_count"`
20132013
}
20142014

build/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ build_android:
4848
cp URnetworkSdk-sources.jar validate/; \
4949
cd validate; \
5050
jar -xf URnetworkSdk-sources.jar; \
51-
bad_exports=`grep -Ri '// skipped' . | grep -v DeviceLocalRpc | grep -ve 'DeviceRemote[A-Z]' | grep -ve 'NewPlatformDeviceLocal' | grep -ve 'Proxy' | grep -ve 'DeviceLocal\.AddReceivePacketCallback' | grep -ve 'DeviceLocal\.Ctx'`; \
51+
bad_exports=`grep -Ri '// skipped' . | grep -v DeviceLocalRpc | grep -ve 'DeviceRemote[A-Z]' | grep -ve 'NewPlatformDeviceLocal' | grep -ve 'Proxy' | grep -ve 'DeviceLocal\.AddReceivePacketCallback' | grep -ve 'DeviceLocal\.Ctx' | grep -ve 'SetEgressSecurityPolicyGenerator' | grep -ve 'SetIngressSecurityPolicyGenerator' | grep -ve 'NewPlatformNetworkSpace'`; \
5252
if [ "$$bad_exports" ]; then \
5353
echo "Some types could not be exported:"; \
5454
echo "$$bad_exports"; \

device_local.go

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ type DeviceLocal struct {
163163
windowStatusChangeListeners *connect.CallbackList[WindowStatusChangeListener]
164164
jwtRefreshListeners *connect.CallbackList[JwtRefreshListener]
165165

166-
localUserNatUnsub func()
166+
localUserNatSub func()
167+
168+
ingressSecurityPolicyGenerator func(*connect.SecurityPolicyStatsCollector) connect.SecurityPolicy
169+
egressSecurityPolicyGenerator func(*connect.SecurityPolicyStatsCollector) connect.SecurityPolicy
167170

168171
viewControllerManager
169172
}
@@ -371,18 +374,28 @@ func newDeviceLocalWithOverrides(
371374
}
372375
deviceLocal.viewControllerManager = *newViewControllerManager(ctx, deviceLocal)
373376

377+
var logout func() error
378+
if networkSpace.asyncLocalState != nil {
379+
logout = networkSpace.asyncLocalState.localState.Logout
380+
} else {
381+
// do nothing
382+
logout = func() error {
383+
return nil
384+
}
385+
}
386+
374387
deviceLocal.tokenManager = newDeviceTokenManager(
375388
ctx,
376389
api,
377390
deviceLocal.SetByJwt,
378391
// TODO the logout event should be propagated to the user
379-
networkSpace.asyncLocalState.localState.Logout,
392+
logout,
380393
)
381394

382395
// set up with nil destination
383396
if provider != nil {
384-
localUserNatUnsub := provider.LocalUserNat().AddReceivePacketCallback(deviceLocal.receive)
385-
deviceLocal.localUserNatUnsub = localUserNatUnsub
397+
localUserNatSub := provider.LocalUserNat().AddReceivePacketCallback(deviceLocal.receive)
398+
deviceLocal.localUserNatSub = localUserNatSub
386399
}
387400

388401
if enableRpc {
@@ -399,6 +412,20 @@ func (self *DeviceLocal) Ctx() context.Context {
399412
return self.ctx
400413
}
401414

415+
// gomobile:ignore
416+
func (self *DeviceLocal) SetIngressSecurityPolicyGenerator(g func(*connect.SecurityPolicyStatsCollector) connect.SecurityPolicy) {
417+
self.stateLock.Lock()
418+
defer self.stateLock.Unlock()
419+
self.ingressSecurityPolicyGenerator = g
420+
}
421+
422+
// gomobile:ignore
423+
func (self *DeviceLocal) SetEgressSecurityPolicyGenerator(g func(*connect.SecurityPolicyStatsCollector) connect.SecurityPolicy) {
424+
self.stateLock.Lock()
425+
defer self.stateLock.Unlock()
426+
self.egressSecurityPolicyGenerator = g
427+
}
428+
402429
func (self *DeviceLocal) RefreshToken(attempt int) error {
403430
self.tokenManager.RefreshToken()
404431
return nil
@@ -461,8 +488,10 @@ func (self *DeviceLocal) client() *connect.Client {
461488
func (self *DeviceLocal) SetByJwt(byJwt string) {
462489
self.GetApi().SetByJwt(byJwt)
463490

464-
self.networkSpace.asyncLocalState.localState.SetByClientJwt(byJwt)
465-
self.networkSpace.asyncLocalState.localState.SetByJwt(byJwt)
491+
if self.networkSpace.asyncLocalState != nil {
492+
self.networkSpace.asyncLocalState.localState.SetByClientJwt(byJwt)
493+
self.networkSpace.asyncLocalState.localState.SetByJwt(byJwt)
494+
}
466495

467496
if self.provider != nil {
468497
self.provider.SetByJwt(byJwt)
@@ -1284,6 +1313,12 @@ func (self *DeviceLocal) SetDestination(location *ConnectLocation, specs *Provid
12841313
}
12851314
settings := connect.DefaultMultiClientSettings()
12861315
settings.DefaultPerformanceProfile = toConnectPerformanceProfile(self.performanceProfile)
1316+
if self.ingressSecurityPolicyGenerator != nil {
1317+
settings.IngressSecurityPolicyGenerator = self.ingressSecurityPolicyGenerator
1318+
}
1319+
if self.egressSecurityPolicyGenerator != nil {
1320+
settings.EgressSecurityPolicyGenerator = self.egressSecurityPolicyGenerator
1321+
}
12871322
multi := connect.NewRemoteUserNatMultiClient(
12881323
self.ctx,
12891324
generator,
@@ -1372,7 +1407,6 @@ func (self *DeviceLocal) SetConnectLocation(location *ConnectLocation) {
13721407
ClientId: location.ConnectLocationId.ClientId,
13731408
BestAvailable: location.ConnectLocationId.BestAvailable,
13741409
})
1375-
13761410
self.SetDestination(location, specs)
13771411
}
13781412
}
@@ -1515,7 +1549,10 @@ func (self *DeviceLocal) Close() {
15151549
self.remoteUserNatClient = nil
15161550
}
15171551
// self.localUserNat.RemoveReceivePacketCallback(self.receive)
1518-
self.localUserNatUnsub()
1552+
if self.localUserNatSub != nil {
1553+
self.localUserNatSub()
1554+
self.localUserNatSub = nil
1555+
}
15191556
if self.remoteUserNatProviderLocalUserNat != nil {
15201557
self.remoteUserNatProviderLocalUserNat.Close()
15211558
self.remoteUserNatProviderLocalUserNat = nil

device_rpc.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,21 @@ func newDeviceRemoteWithOverrides(
235235

236236
deviceRemote.viewControllerManager = *newViewControllerManager(ctx, deviceRemote)
237237

238+
var logout func() error
239+
if networkSpace.asyncLocalState != nil {
240+
logout = networkSpace.asyncLocalState.localState.Logout
241+
} else {
242+
// do nothing
243+
logout = func() error {
244+
return nil
245+
}
246+
}
247+
238248
deviceRemote.tokenManager = newDeviceTokenManager(
239249
ctx,
240250
api,
241251
deviceRemote.setByJwt,
242-
networkSpace.asyncLocalState.localState.Logout,
252+
logout,
243253
)
244254

245255
api.setHttpPostRaw(deviceRemote.httpPostRaw)
@@ -500,8 +510,10 @@ func (self *DeviceRemote) setByJwt(byJwt string) {
500510

501511
self.GetApi().SetByJwt(byJwt)
502512

503-
self.networkSpace.asyncLocalState.localState.SetByClientJwt(byJwt)
504-
self.networkSpace.asyncLocalState.localState.SetByJwt(byJwt)
513+
if self.networkSpace.asyncLocalState != nil {
514+
self.networkSpace.asyncLocalState.localState.SetByClientJwt(byJwt)
515+
self.networkSpace.asyncLocalState.localState.SetByJwt(byJwt)
516+
}
505517

506518
func() {
507519
self.stateLock.Lock()

network_space.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ type NetExtenderAutoConfigure struct {
3939
}
4040

4141
type ExportNetworkSpace struct {
42-
Key *NetworkSpaceKey `json:"key,omitempty"`
43-
Values *NetworkSpaceValues `json:"values,omitempty"`
42+
Key *NetworkSpaceKey `json:"key,omitempty"`
43+
Values *NetworkSpaceValues `json:"values,omitempty"`
4444
}
4545

4646
type NetworkSpaceKey struct {
@@ -172,14 +172,28 @@ func newNetworkSpace(
172172
}
173173
}
174174

175+
// gomobile:ignore
176+
func NewPlatformNetworkSpace(
177+
ctx context.Context,
178+
env string,
179+
host string,
180+
) *NetworkSpace {
181+
key := NetworkSpaceKey{
182+
EnvName: env,
183+
HostName: host,
184+
}
185+
values := NetworkSpaceValues{}
186+
return newNetworkSpace(ctx, key, values, "")
187+
}
188+
175189
func testing_newNetworkSpace(ctx context.Context) (networkSpace *NetworkSpace, byJwt string, returnErr error) {
176190
key := NetworkSpaceKey{
177191
HostName: "test",
178-
EnvName: "test",
192+
EnvName: "test",
179193
}
180194
values := NetworkSpaceValues{
181-
Bundled: true,
182-
NetExposeServerIps: true,
195+
Bundled: true,
196+
NetExposeServerIps: true,
183197
NetExposeServerHostNames: true,
184198
}
185199
storagePath, err := os.MkdirTemp("", "networkspace")
@@ -286,7 +300,7 @@ func (self *NetworkSpace) close() {
286300

287301
func (self *NetworkSpace) ToJson() (string, error) {
288302
exportNetworkSpace := &ExportNetworkSpace{
289-
Key: &self.key,
303+
Key: &self.key,
290304
Values: &self.values,
291305
}
292306
networkSpaceJsonBytes, err := json.Marshal(exportNetworkSpace)

0 commit comments

Comments
 (0)