mirror of
https://github.com/amnezia-vpn/amneziawg-go.git
synced 2025-04-16 22:16:55 +02:00
migrate counter
This commit is contained in:
parent
553060f804
commit
e08105f85b
2 changed files with 10 additions and 5 deletions
|
@ -3,13 +3,15 @@ package adapter
|
|||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/aarzilli/golua/lua"
|
||||
)
|
||||
|
||||
// TODO: aSec sync is enough?
|
||||
type Lua struct {
|
||||
state *lua.State
|
||||
state *lua.State
|
||||
packetCounter atomic.Int64
|
||||
}
|
||||
|
||||
type LuaParams struct {
|
||||
|
@ -36,12 +38,15 @@ func (l *Lua) Close() {
|
|||
l.state.Close()
|
||||
}
|
||||
|
||||
func (l *Lua) Generate(msgType int64, data []byte, counter int64) ([]byte, error) {
|
||||
func (l *Lua) Generate(
|
||||
msgType int64,
|
||||
data []byte,
|
||||
) ([]byte, error) {
|
||||
l.state.GetGlobal("d_gen")
|
||||
|
||||
l.state.PushInteger(msgType)
|
||||
l.state.PushBytes(data)
|
||||
l.state.PushInteger(counter)
|
||||
l.state.PushInteger(l.packetCounter.Add(1))
|
||||
|
||||
if err := l.state.Call(3, 1); err != nil {
|
||||
return nil, fmt.Errorf("Error calling Lua function: %v\n", err)
|
||||
|
|
|
@ -26,7 +26,7 @@ func TestLua_Generate(t *testing.T) {
|
|||
t.Run("", func(t *testing.T) {
|
||||
l := newLua()
|
||||
defer l.Close()
|
||||
got, err := l.Generate(1, []byte("test"), 10)
|
||||
got, err := l.Generate(1, []byte("test"))
|
||||
if err != nil {
|
||||
t.Errorf(
|
||||
"Lua.Generate() error = %v, wantErr %v",
|
||||
|
@ -36,7 +36,7 @@ func TestLua_Generate(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
want := "10headertest"
|
||||
want := "1headertest"
|
||||
if string(got) != want {
|
||||
t.Errorf("Lua.Generate() = %v, want %v", string(got), want)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue