github.com/tetratelabs/proxy-wasm-go-sdk@v0.23.1-0.20240517021853-021aa9cf78e8/proxywasm/internal/abi_callback_l4.go (about) 1 // Copyright 2020-2021 Tetrate 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package internal 16 17 import ( 18 "time" 19 20 "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" 21 ) 22 23 //export proxy_on_new_connection 24 func proxyOnNewConnection(contextID uint32) types.Action { 25 if recordTiming { 26 defer logTiming("proxyOnNewConnection", time.Now()) 27 } 28 ctx, ok := currentState.tcpContexts[contextID] 29 if !ok { 30 panic("invalid context") 31 } 32 currentState.setActiveContextID(contextID) 33 return ctx.OnNewConnection() 34 } 35 36 //export proxy_on_downstream_data 37 func proxyOnDownstreamData(contextID uint32, dataSize int, endOfStream bool) types.Action { 38 if recordTiming { 39 defer logTiming("proxyOnDownstreamData", time.Now()) 40 } 41 ctx, ok := currentState.tcpContexts[contextID] 42 if !ok { 43 panic("invalid context") 44 } 45 currentState.setActiveContextID(contextID) 46 return ctx.OnDownstreamData(dataSize, endOfStream) 47 } 48 49 //export proxy_on_downstream_connection_close 50 func proxyOnDownstreamConnectionClose(contextID uint32, pType types.PeerType) { 51 if recordTiming { 52 defer logTiming("proxyOnDownstreamConnectionClose", time.Now()) 53 } 54 ctx, ok := currentState.tcpContexts[contextID] 55 if !ok { 56 panic("invalid context") 57 } 58 currentState.setActiveContextID(contextID) 59 ctx.OnDownstreamClose(pType) 60 } 61 62 //export proxy_on_upstream_data 63 func proxyOnUpstreamData(contextID uint32, dataSize int, endOfStream bool) types.Action { 64 if recordTiming { 65 defer logTiming("proxyOnUpstreamData", time.Now()) 66 } 67 ctx, ok := currentState.tcpContexts[contextID] 68 if !ok { 69 panic("invalid context") 70 } 71 currentState.setActiveContextID(contextID) 72 return ctx.OnUpstreamData(dataSize, endOfStream) 73 } 74 75 //export proxy_on_upstream_connection_close 76 func proxyOnUpstreamConnectionClose(contextID uint32, pType types.PeerType) { 77 if recordTiming { 78 defer logTiming("proxyOnUpstreamConnectionClose", time.Now()) 79 } 80 ctx, ok := currentState.tcpContexts[contextID] 81 if !ok { 82 panic("invalid context") 83 } 84 currentState.setActiveContextID(contextID) 85 ctx.OnUpstreamClose(pType) 86 }