Skip to content

Commit 076bd2b

Browse files
committed
updates
1 parent 95b18da commit 076bd2b

7 files changed

Lines changed: 65 additions & 53 deletions

File tree

connect/resident.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ func (self *Exchange) Close() {
819819
type ExchangeBuffer struct {
820820
settings *ExchangeSettings
821821

822-
framer *connect.MessageFramer
822+
framer *connect.Framer
823823
}
824824

825825
func NewDefaultExchangeBuffer(settings *ExchangeSettings) *ExchangeBuffer {

connect/resident_proxy.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@ package main
22

33
// FIXME have a multi client in the proxy, set proxy as the generator
44

5-
65
import (
76
"context"
87

98
"github.com/urnetwork/sdk"
10-
119
)
1210

1311
type ResidentProxyDevice struct {
14-
ctx context.Context
15-
cancel context.CancelFun
12+
ctx context.Context
13+
cancel context.CancelFunc
1614

1715
deviceLocal *sdk.DeviceLocal
18-
19-
2016
}
2117

2218
func CreateResidentProxyDevice(
@@ -52,12 +48,12 @@ func (self *ResidentProxyDevice) AddTun() (
5248
send chan []byte,
5349
receive chan []byte,
5450
closeTun func(),
55-
) func() {
51+
) {
5652
tunCtx, tunCancel := context.WithCancel(ctx)
5753

5854
for {
5955
select {
60-
case packet := <- receive:
56+
case packet := <-receive:
6157
self.deviceLocal.Write(packet)
6258
RELEASE(packet)
6359

@@ -83,4 +79,3 @@ func (self *ResidentProxyDevice) Close() {
8379

8480
self.deviceLocal.Close()
8581
}
86-

connect/transport_proxy.go

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
11
package main
22

3-
4-
// http proxy and socks proxy connections.
5-
//
3+
// http proxy and socks proxy connections.
4+
//
65
// run the http proxy on the connect service and form the proxy connection via an ExchangeConnection to the resident
7-
//
6+
//
87

98
// run the socks proxy on the connect service and form the proxy conenction via an ExchangeConnection to the resident
109

11-
12-
13-
type ConnectHandlerSettings struct {
14-
WriteTimeout time.Duration
15-
ReadTimeout time.Duration
16-
ProxyConnectionIdleTimeout. time.Duration
17-
ListenSocksPort int
18-
FramerSettings *connect.FramerSettings
10+
type ProxyConnectHandlerSettings struct {
11+
WriteTimeout time.Duration
12+
ReadTimeout time.Duration
13+
ProxyConnectionIdleTimeout time.Duration
14+
ListenSocksPort int
15+
FramerSettings *connect.FramerSettings
1916
}
2017

2118
// FIXME hook up framer to tun device packet write/read
2219

23-
24-
2520
type ProxyConnectHandler struct {
2621

27-
2822
//
2923

3024
}
3125

3226
func NewProxyConnectHandler() {
3327

34-
// FIXME create tnet per client id, route output of tnet to
35-
28+
// FIXME create tnet per client id, route output of tnet to
3629

3730
proxy := goproxy.NewProxyHttpServer()
3831

@@ -54,18 +47,16 @@ func NewProxyConnectHandler() {
5447
return tnet.DialContext(req.Context(), network, addr)
5548
}
5649

57-
5850
}
5951

6052
func connectProxy() {
6153
// FIXME
62-
54+
6355
// if not exists, create a new one
6456
// each network action, record activity. Close connection if no activity in Timeout
6557

6658
// the tnet packets are written/read to the exchange transport
6759

68-
6960
}
7061

7162
// http proxy
@@ -84,9 +75,6 @@ func (self *ProxyConnectHandler) runSocks() {
8475
// FIXME write to the local SOCKS proxy
8576
// FIXME packet output from the local http proxy should be written to a TUN transport to the resident
8677

87-
88-
89-
9078
server := socks5.NewServer(
9179
socks5.WithLogger(self),
9280
socks5.WithAuthMethods([]Authenticator{
@@ -111,17 +99,15 @@ func (self *ProxyConnectHandler) runSocks() {
11199
return nil, fmt.Errorf("Unsupported network: %s", network)
112100
}
113101
}),
114-
115102
)
116103

117104
server.ListenAndServe("tcp", self.settings.ListenSocksPort)
118105

119-
120106
}
121107

122108
// socks.Logger
123109
func (self *SocksLogger) Errorf(format string, args ...any) {
124-
glog.Errorf("[tp]" + format, args...)
110+
glog.Errorf("[tp]"+format, args...)
125111
}
126112

127113
// socks.CredentialStore
@@ -142,4 +128,3 @@ func (self *ProxyConnectHandler) Resolve(ctx context.Context, name string) (cont
142128
ip := net.Ip(addr.AsSlice())
143129
return ctx, ip, nil
144130
}
145-

db_migrations.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,4 +2664,19 @@ var migrations = []any{
26642664
DROP CONSTRAINT client_connection_reliability_score_pkey,
26652665
ADD PRIMARY KEY (client_id, lookback_index)
26662666
`),
2667+
2668+
newSqlMigration(`
2669+
CREATE TABLE proxy_device_config (
2670+
proxy_id uuid NOT NULL,
2671+
client_id uuid NOT NULL,
2672+
instance_id uuid NOT NULL,
2673+
config_json TEXT NOT NULL,
2674+
2675+
PRIMARY KEY (proxy_id)
2676+
)
2677+
`),
2678+
2679+
newSqlMigration(`
2680+
CREATE UNIQUE INDEX proxy_device_config_client_id_instance_id ON proxy_device_config (client_id, instance_id)
2681+
`),
26672682
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ require (
3030
github.com/stripe/stripe-go/v82 v82.5.1
3131
github.com/tyler-smith/go-bip39 v1.1.0
3232
github.com/urnetwork/connect v0.0.0
33-
github.com/urnetwork/sdk v0.0.0
3433
github.com/urnetwork/glog v0.0.0
34+
github.com/urnetwork/sdk v0.0.0
3535
golang.org/x/crypto v0.46.0
3636
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93
3737
google.golang.org/protobuf v1.36.11
@@ -43,6 +43,7 @@ require (
4343
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251001021608-1fe7b43fc4d6 // indirect
4444
github.com/bits-and-blooms/bitset v1.20.0 // indirect
4545
github.com/blendle/zapdriver v1.3.1 // indirect
46+
github.com/btcsuite/btcutil v1.0.2 // indirect
4647
github.com/consensys/gnark-crypto v0.18.0 // indirect
4748
github.com/crate-crypto/go-eth-kzg v1.4.0 // indirect
4849
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect

go.sum

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDO
66
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
77
github.com/TwiN/go-away v1.8.0 h1:9eNCSlbVe9vjrBCC69afH/XR0lfKQL27IDzUlqoPEmQ=
88
github.com/TwiN/go-away v1.8.0/go.mod h1:FEnYVbC7/xfbBDN4iQ2W/ZQ6+UvnyUBYUk7cZgHocWs=
9+
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
910
github.com/aws/aws-sdk-go v1.55.8 h1:JRmEUbU52aJQZ2AjX4q4Wu7t4uZjOu71uyNmaWlUkJQ=
1011
github.com/aws/aws-sdk-go v1.55.8/go.mod h1:ZkViS9AqA6otK+JBBNH2++sx1sgxrPKcSzPPvQkUtXk=
1112
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
@@ -19,6 +20,16 @@ github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
1920
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
2021
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
2122
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
23+
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
24+
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
25+
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
26+
github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2uts=
27+
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
28+
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
29+
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
30+
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
31+
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
32+
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
2233
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
2334
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
2435
github.com/consensys/gnark-crypto v0.18.0 h1:vIye/FqI50VeAr0B3dx+YjeIvmc3LWz4yEfbWBpTUf0=
@@ -29,6 +40,7 @@ github.com/crate-crypto/go-eth-kzg v1.4.0 h1:WzDGjHk4gFg6YzV0rJOAsTK4z3Qkz5jd4RE
2940
github.com/crate-crypto/go-eth-kzg v1.4.0/go.mod h1:J9/u5sWfznSObptgfa92Jq8rTswn6ahQWEuiLHOjCUI=
3041
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a h1:W8mUrRp6NOVl3J+MYp5kPMoUZPp7aOYHtaua31lwRHg=
3142
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a/go.mod h1:sTwzHBvIzm2RfVCGNEBZgRyjwK40bVoun3ZnGOCafNM=
43+
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3244
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3345
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3446
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -99,13 +111,16 @@ github.com/jackc/pgx/v5 v5.8.0 h1:TYPDoleBBme0xGSAX3/+NujXXtpZn9HBONkQC7IEZSo=
99111
github.com/jackc/pgx/v5 v5.8.0/go.mod h1:QVeDInX2m9VyzvNeiCJVjCkNFqzsNb43204HshNSZKw=
100112
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
101113
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
114+
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
102115
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
103116
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
104117
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
105118
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
119+
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
106120
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
107121
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
108122
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
123+
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
109124
github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
110125
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
111126
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
@@ -159,7 +174,9 @@ github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNs
159174
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
160175
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
161176
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
177+
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
162178
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
179+
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
163180
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
164181
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
165182
github.com/oschwald/maxminddb-golang/v2 v2.1.1 h1:lA8FH0oOrM4u7mLvowq8IT6a3Q/qEnqRzLQn9eH5ojc=
@@ -244,8 +261,10 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
244261
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
245262
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
246263
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
264+
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
247265
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
248266
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
267+
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
249268
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
250269
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
251270
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
@@ -342,6 +361,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
342361
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
343362
gopkg.in/ini.v1 v1.55.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
344363
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
364+
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
345365
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
346366
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
347367
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

model/subscription_model.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,7 +2550,7 @@ func ForceCloseOpenContractIds(ctx context.Context, minTime time.Time, maxCount
25502550
return nil
25512551
}
25522552

2553-
nextIndex := parallel
2553+
nextIndex := 0
25542554
var nextIndexLock sync.Mutex
25552555
getAndIncrNextIndex := func() int {
25562556
nextIndexLock.Lock()
@@ -2561,15 +2561,15 @@ func ForceCloseOpenContractIds(ctx context.Context, minTime time.Time, maxCount
25612561
return i
25622562
}
25632563

2564-
workerCtxs := []context.Context{}
2565-
for j0 := range parallel {
2566-
workerCtx, workerCancel := context.WithCancel(ctx)
2567-
workerCtxs = append(workerCtxs, workerCtx)
2564+
var wg sync.WaitGroup
2565+
2566+
for range parallel {
2567+
wg.Add(1)
25682568
go server.HandleError(func() {
2569-
defer workerCancel()
2570-
for j := j0; j < len(openContracts); j = getAndIncrNextIndex() {
2569+
defer wg.Done()
2570+
for j := getAndIncrNextIndex(); j < len(openContracts); j = getAndIncrNextIndex() {
25712571
select {
2572-
case <-workerCtx.Done():
2572+
case <-ctx.Done():
25732573
return
25742574
default:
25752575
}
@@ -2584,15 +2584,11 @@ func ForceCloseOpenContractIds(ctx context.Context, minTime time.Time, maxCount
25842584
}
25852585
})
25862586
}
2587-
}, workerCancel)
2587+
})
25882588
}
25892589

2590-
// wait for all workers
2591-
for _, workerCtx := range workerCtxs {
2592-
select {
2593-
case <-workerCtx.Done():
2594-
}
2595-
}
2590+
wg.Wait()
2591+
25962592
closeCount += int64(len(openContracts))
25972593

25982594
return

0 commit comments

Comments
 (0)