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

Commit cf6ad74

Browse files
committed
pass rootContextID to new{http,stream}Context
Signed-off-by: mathetake <[email protected]>
1 parent 04c9acd commit cf6ad74

File tree

10 files changed

+24
-24
lines changed

10 files changed

+24
-24
lines changed

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
}

proxywasm/vmstate_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ func TestSetNewHttpContext(t *testing.T) {
2929
defer currentStateMux.Unlock()
3030

3131
var cnt int
32-
f := func(uint32) HttpContext {
32+
f := func(uint32, uint32) HttpContext {
3333
cnt++
3434
return nil
3535
}
3636
SetNewHttpContext(f)
37-
currentState.newHttpContext(0)
37+
currentState.newHttpContext(0, 0)
3838
assert.Equal(t, 1, cnt)
3939
}
4040

@@ -43,12 +43,12 @@ func TestSetNewStreamContext(t *testing.T) {
4343
defer currentStateMux.Unlock()
4444

4545
var cnt int
46-
f := func(uint32) StreamContext {
46+
f := func(uint32, uint32) StreamContext {
4747
cnt++
4848
return nil
4949
}
5050
SetNewStreamContext(f)
51-
currentState.newStreamContext(0)
51+
currentState.newStreamContext(0, 0)
5252
assert.Equal(t, 1, cnt)
5353
}
5454

@@ -86,7 +86,7 @@ func TestState_createStreamContext(t *testing.T) {
8686
s := &state{
8787
rootContexts: map[uint32]*rootContextState{rid: nil},
8888
streams: map[uint32]StreamContext{},
89-
newStreamContext: func(contextID uint32) StreamContext { return &sc{} },
89+
newStreamContext: func(rootContextID, contextID uint32) StreamContext { return &sc{} },
9090
contextIDToRooID: map[uint32]uint32{},
9191
}
9292

@@ -107,7 +107,7 @@ func TestState_createHttpContext(t *testing.T) {
107107
s := &state{
108108
rootContexts: map[uint32]*rootContextState{rid: nil},
109109
httpStreams: map[uint32]HttpContext{},
110-
newHttpContext: func(contextID uint32) HttpContext { return &hc{} },
110+
newHttpContext: func(rootContextID, contextID uint32) HttpContext { return &hc{} },
111111
contextIDToRooID: map[uint32]uint32{},
112112
}
113113

0 commit comments

Comments
 (0)