Skip to content

Commit

Permalink
plasma v1.0.1 adoption
Browse files Browse the repository at this point in the history
  • Loading branch information
shoriwe committed Aug 23, 2022
1 parent 2bbc2c1 commit 5658709
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 30 deletions.
18 changes: 9 additions & 9 deletions debug/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def test_socks5_with_http_no_auth():


def test_socks5_with_http_with_file_auth():
#assert requests.get(
# "http://127.0.0.1:8080",
# proxies={
# "http": "socks5://sulcud:[email protected]:9050",
# "https": "socks5://sulcud:[email protected]:9050"
# }
#)
# assert requests.get(
# "http://127.0.0.1:8000",
# proxies={
# "http": "socks5://sulcud:[email protected]:9050",
# "https": "socks5://sulcud:[email protected]:9050"
# }
# )
assert requests.get(
"https://google.com",
proxies={
Expand All @@ -77,8 +77,8 @@ def main():

# test_socks5_with_http_no_auth()

test_http_with_http_no_auth()
# test_socks5_with_http_with_file_auth()
#test_http_with_http_no_auth()
test_socks5_with_http_with_file_auth()


if __name__ == '__main__':
Expand Down
22 changes: 13 additions & 9 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
func authScript(username, password []byte) []byte {
bytecode, _ := assembler.Assemble(
ast3.Program{
ast3.Call{
&ast3.Call{
Function: &ast3.Selector{
X: &ast3.Identifier{
Symbol: "-driver",
Expand All @@ -45,7 +45,7 @@ func authScript(username, password []byte) []byte {
func inboundScript(address []byte) []byte {
bytecode, _ := assembler.Assemble(
ast3.Program{
ast3.Call{
&ast3.Call{
Function: &ast3.Selector{
X: &ast3.Identifier{
Symbol: "-driver",
Expand All @@ -68,7 +68,7 @@ func inboundScript(address []byte) []byte {
func outboundScript(address []byte) []byte {
bytecode, _ := assembler.Assemble(
ast3.Program{
ast3.Call{
&ast3.Call{
Function: &ast3.Selector{
X: &ast3.Identifier{
Symbol: "-driver",
Expand All @@ -91,7 +91,7 @@ func outboundScript(address []byte) []byte {
func listenScript(address []byte) []byte {
bytecode, _ := assembler.Assemble(
ast3.Program{
ast3.Call{
&ast3.Call{
Function: &ast3.Selector{
X: &ast3.Identifier{
Symbol: "-driver",
Expand All @@ -114,7 +114,7 @@ func listenScript(address []byte) []byte {
func acceptScript(address []byte) []byte {
bytecode, _ := assembler.Assemble(
ast3.Program{
ast3.Call{
&ast3.Call{
Function: &ast3.Selector{
X: &ast3.Identifier{
Symbol: "-driver",
Expand Down Expand Up @@ -238,23 +238,27 @@ func (d *Driver) Accept(address string) error {
return nil
}

func (r *runner) loadDriver(script string) (*Driver, error) {
func (r *runner) loadDriver(scriptPath string) (*Driver, error) {
scriptContents, readError := os.ReadFile(scriptPath)
if readError != nil {
return nil, readError
}
d := &Driver{
plasma: initializeVM(),
}
// Setup the names used by the script
_, errorChannel, _ := d.plasma.ExecuteString(script)
_, errorChannel, _ := d.plasma.ExecuteString(string(scriptContents))
//

if err := <-errorChannel; err != nil {
return nil, errors.New("driver script execution error")
return nil, err
}
return d, nil
}

func initializeVM() *vm.Plasma {
plasma := vm.NewVM(os.Stdin, os.Stdout, os.Stderr)
plasma.Load("-driver", func(_ *vm.Plasma) *vm.Value { return plasma.None() })
plasma.Load("-driver", func(_ *vm.Plasma) *vm.Value { return plasma.Value() })
plasma.Load("set_auth",
func(p *vm.Plasma) *vm.Value {
return p.NewBuiltInFunction(
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/gorilla/websocket v1.5.0
github.com/shoriwe/gplasma v1.0.1
github.com/shoriwe/gplasma v1.0.2
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/net v0.0.0-20210908191846-a5e095526f91
gopkg.in/elazarl/goproxy.v1 v1.0.0-20180725130230-947c36da3153
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/shoriwe/gplasma v1.0.1 h1:q4peogYDCTSWrSKWNP8+OLvmDWMdEeS7wsT3hF69EOc=
github.com/shoriwe/gplasma v1.0.1/go.mod h1:f9gs3jQQMWvY+XCbKe1oB7xpiJSuU5FjKQvP9aNs2Ko=
github.com/shoriwe/gplasma v1.0.2 h1:M3+Q6WzYjxVwoCpq6mZWpufLV42SB88ViSFnzC3h4QE=
github.com/shoriwe/gplasma v1.0.2/go.mod h1:f9gs3jQQMWvY+XCbKe1oB7xpiJSuU5FjKQvP9aNs2Ko=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.0.0-20210908191846-a5e095526f91 h1:E8wdt+zBjoxD3MA65wEc3pl25BsTi7tbkpwc4ANThjc=
Expand Down
4 changes: 2 additions & 2 deletions sample-config/configs/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ services:
network: tcp
address: 127.0.0.1:9050
filters:
#inbound: filter
#outbound: filter
# inbound: filter
outbound: filter
listen: filter
accept: filter
protocol:
Expand Down
4 changes: 2 additions & 2 deletions sample-config/scripts/auth.pm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def basic_login(username, password)
if username == "sulcud" and password == "password"
return True
return true
end
return False
return false
end

set_auth(basic_login)
4 changes: 2 additions & 2 deletions sample-config/scripts/filter.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
def no_localhost(address)
if "127.0.0.1" in address
return False
return false
elif "localhost" in address
return false
end
return True
return true
end

set_inbound(no_localhost)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# github.com/gorilla/websocket v1.5.0
## explicit; go 1.12
github.com/gorilla/websocket
# github.com/shoriwe/gplasma v1.0.1
# github.com/shoriwe/gplasma v1.0.2
## explicit; go 1.18
github.com/shoriwe/gplasma/pkg/ast
github.com/shoriwe/gplasma/pkg/ast2
Expand Down

0 comments on commit 5658709

Please sign in to comment.