Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 0e8ae5f

Browse files
authored
Merge pull request #71 from tetratelabs/refactoring
pass rootContextID to new{http,stream}Context
2 parents 29b5de7 + 0766531 commit 0e8ae5f

File tree

11 files changed

+25
-25
lines changed

11 files changed

+25
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ TinyGo's official release of WASI target will come soon, and after that you coul
5757
| proxy-wasm-go-sdk| proxy-wasm ABI version |istio/proxyv2|
5858
|:-------------:|:-------------:|:-------------:|
5959
| main | 0.2.0| v1.17.x |
60-
| v0.0.4 | 0.2.0| v1.17.x |
60+
| v0.0.6 | 0.2.0| v1.17.x |
6161

6262

6363
## run examples

examples/http_auth_random/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type httpAuthRandom struct {
3333
contextID uint32
3434
}
3535

36-
func newContext(contextID uint32) proxywasm.HttpContext {
36+
func newContext(rootContextID, contextID uint32) proxywasm.HttpContext {
3737
return &httpAuthRandom{contextID: contextID}
3838
}
3939

examples/http_headers/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type httpHeaders struct {
2929
contextID uint32
3030
}
3131

32-
func newContext(contextID uint32) proxywasm.HttpContext {
32+
func newContext(rootContextID, contextID uint32) proxywasm.HttpContext {
3333
return &httpHeaders{contextID: contextID}
3434
}
3535

examples/metrics/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type metricHttpContext struct {
4848
proxywasm.DefaultHttpContext
4949
}
5050

51-
func newHttpContext(uint32) proxywasm.HttpContext {
51+
func newHttpContext(uint32, uint32) proxywasm.HttpContext {
5252
return &metricHttpContext{}
5353
}
5454

examples/network/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type networkContext struct {
4848
proxywasm.DefaultStreamContext
4949
}
5050

51-
func newNetworkContext(uint32) proxywasm.StreamContext {
51+
func newNetworkContext(uint32, uint32) proxywasm.StreamContext {
5252
return &networkContext{}
5353
}
5454

examples/shared_data/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func newRootContext(uint32) proxywasm.RootContext {
4040
return &sharedDataRootContext{}
4141
}
4242

43-
func newHttpContext(uint32) proxywasm.HttpContext {
43+
func newHttpContext(uint32, uint32) proxywasm.HttpContext {
4444
return &sharedDataHttpContext{}
4545
}
4646

examples/shared_queue/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type queueHttpContext struct {
7474
proxywasm.DefaultHttpContext
7575
}
7676

77-
func newHttpContext(uint32) proxywasm.HttpContext {
77+
func newHttpContext(uint32, uint32) proxywasm.HttpContext {
7878
return &queueHttpContext{}
7979
}
8080

proxytest/option.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
55
type EmulatorOption struct {
66
pluginConfiguration, vmConfiguration []byte
77
newRootContext func(uint32) proxywasm.RootContext
8-
newStreamContext func(uint32) proxywasm.StreamContext
9-
newHttpContext func(uint32) proxywasm.HttpContext
8+
newStreamContext func(uint32, uint32) proxywasm.StreamContext
9+
newHttpContext func(uint32, uint32) proxywasm.HttpContext
1010
}
1111

1212
func NewEmulatorOption() *EmulatorOption {
@@ -18,12 +18,12 @@ func (o *EmulatorOption) WithNewRootContext(f func(uint32) proxywasm.RootContext
1818
return o
1919
}
2020

21-
func (o *EmulatorOption) WithNewHttpContext(f func(uint32) proxywasm.HttpContext) *EmulatorOption {
21+
func (o *EmulatorOption) WithNewHttpContext(f func(uint32, uint32) proxywasm.HttpContext) *EmulatorOption {
2222
o.newHttpContext = f
2323
return o
2424
}
2525

26-
func (o *EmulatorOption) WithNewStreamContext(f func(uint32) proxywasm.StreamContext) *EmulatorOption {
26+
func (o *EmulatorOption) WithNewStreamContext(f func(uint32, uint32) proxywasm.StreamContext) *EmulatorOption {
2727
o.newStreamContext = f
2828
return o
2929
}

proxywasm/abi_lifecycle_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ func Test_proxyOnContextCreate(t *testing.T) {
2727

2828
proxyOnContextCreate(100, 0)
2929
require.Equal(t, 1, cnt)
30-
SetNewHttpContext(func(contextID uint32) HttpContext {
30+
SetNewHttpContext(func(rootContextID, contextID uint32) HttpContext {
3131
cnt += 100
3232
return nil
3333
})
3434
proxyOnContextCreate(100, 100)
3535
require.Equal(t, 101, cnt)
3636
currentState.newHttpContext = nil
3737

38-
SetNewStreamContext(func(contextID uint32) StreamContext {
38+
SetNewStreamContext(func(rootContextID, contextID uint32) StreamContext {
3939
cnt += 1000
4040
return nil
4141
})

proxywasm/vmstate.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ type (
2929
type state struct {
3030
newRootContext func(contextID uint32) RootContext
3131
rootContexts map[uint32]*rootContextState
32-
newStreamContext func(contextID uint32) StreamContext
32+
newStreamContext func(rootContextID, contextID uint32) StreamContext
3333
streams map[uint32]StreamContext
34-
newHttpContext func(contextID uint32) HttpContext
34+
newHttpContext func(rootContextID, contextID uint32) HttpContext
3535
httpStreams map[uint32]HttpContext
3636

3737
contextIDToRooID map[uint32]uint32
@@ -49,11 +49,11 @@ func SetNewRootContext(f func(contextID uint32) RootContext) {
4949
currentState.newRootContext = f
5050
}
5151

52-
func SetNewHttpContext(f func(contextID uint32) HttpContext) {
52+
func SetNewHttpContext(f func(rootContextID, contextID uint32) HttpContext) {
5353
currentState.newHttpContext = f
5454
}
5555

56-
func SetNewStreamContext(f func(contextID uint32) StreamContext) {
56+
func SetNewStreamContext(f func(rootContextID, contextID uint32) StreamContext) {
5757
currentState.newStreamContext = f
5858
}
5959

@@ -84,7 +84,7 @@ func (s *state) createStreamContext(contextID uint32, rootContextID uint32) {
8484
panic("context id duplicated")
8585
}
8686

87-
ctx := s.newStreamContext(contextID)
87+
ctx := s.newStreamContext(rootContextID, contextID)
8888
s.contextIDToRooID[contextID] = rootContextID
8989
s.streams[contextID] = ctx
9090
}
@@ -98,7 +98,7 @@ func (s *state) createHttpContext(contextID uint32, rootContextID uint32) {
9898
panic("context id duplicated")
9999
}
100100

101-
ctx := s.newHttpContext(contextID)
101+
ctx := s.newHttpContext(rootContextID, contextID)
102102
s.contextIDToRooID[contextID] = rootContextID
103103
s.httpStreams[contextID] = ctx
104104
}

0 commit comments

Comments
 (0)