diff --git a/README.md b/README.md new file mode 100644 index 0000000..76a8f03 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Spaceship AAR +Using gomobile to generate the native AAR for Android. (or IOS?) + +## Usage +You may use it in your Android program, that's pretty convenient than executing the program binary. + +## Generate +You have to ensure that you have gomobile already installed in your go mod, then execute the following: + +```bash +gomobile bind -target android/arm64 . +``` + +## Limitation +Since the gomobile only support very basic few types in class converter, it's better to pass a full configuration string +which represents the whole config structure in json format. + +## Disclaimer +This repo or its generated library are for study purpose only, absolutely without any warranty, use it at your own risk. \ No newline at end of file diff --git a/config.go b/config.go new file mode 100644 index 0000000..35503c4 --- /dev/null +++ b/config.go @@ -0,0 +1,28 @@ +package spaceship_aar + +import "encoding/json" + +// since go-mobile only support basic types, some fields are minimized + +type Config struct { + Path string `json:"path"` + Host string `json:"host"` + ServerAddr string `json:"server_addr"` + Uuid string `json:"uuid"` + ListenSocks string `json:"listen_socks"` + ListenHttp string `json:"listen_http"` + Tls bool `json:"tls"` + Mux int `json:"mux"` + Buffer int `json:"buffer"` + DNS string `json:"dns"` + CA string `json:"ca"` + Log string `json:"log"` +} + +func (c *Config) ToJson() string { + b, err := json.Marshal(c) + if err != nil { + return "" + } + return string(b) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b5d3f5f --- /dev/null +++ b/go.mod @@ -0,0 +1,18 @@ +module spaceship_aar + +go 1.19 + +require ( + github.com/SuzukiHonoka/spaceship v1.4.6-rc // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/uuid v1.3.0 // indirect + golang.org/x/mobile v0.0.0-20221110043201-43a038452099 // indirect + golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect + golang.org/x/net v0.5.0 // indirect + golang.org/x/sys v0.4.0 // indirect + golang.org/x/text v0.6.0 // indirect + golang.org/x/tools v0.1.12 // indirect + google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 // indirect + google.golang.org/grpc v1.52.3 // indirect + google.golang.org/protobuf v1.28.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7fadacb --- /dev/null +++ b/go.sum @@ -0,0 +1,29 @@ +github.com/SuzukiHonoka/spaceship v1.4.6-rc h1:qluK7lYLsgI/wwFyRXU1Ye9LJmQTZ3U8nsPE7lRo7ak= +github.com/SuzukiHonoka/spaceship v1.4.6-rc/go.mod h1:/1FFphcj9KpIm+kgIia6R5PdPszpnrwjujrwR3qa7vM= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +golang.org/x/mobile v0.0.0-20221110043201-43a038452099 h1:aIu0lKmfdgtn2uTj7JI2oN4TUrQvgB+wzTPO23bCKt8= +golang.org/x/mobile v0.0.0-20221110043201-43a038452099/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 h1:vArvWooPH749rNHpBGgVl+U9B9dATjiEhJzcWGlovNs= +google.golang.org/genproto v0.0.0-20230202175211-008b39050e57/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= +google.golang.org/grpc v1.52.3 h1:pf7sOysg4LdgBqduXveGKrcEwbStiK2rtfghdzlUYDQ= +google.golang.org/grpc v1.52.3/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/proxy.go b/proxy.go new file mode 100644 index 0000000..1de575a --- /dev/null +++ b/proxy.go @@ -0,0 +1,52 @@ +package spaceship_aar + +import ( + "encoding/json" + "github.com/SuzukiHonoka/spaceship/api" + "github.com/SuzukiHonoka/spaceship/pkg/config" + "github.com/SuzukiHonoka/spaceship/pkg/config/client" + "github.com/SuzukiHonoka/spaceship/pkg/config/server" + "github.com/SuzukiHonoka/spaceship/pkg/dns" + "github.com/SuzukiHonoka/spaceship/pkg/logger" +) + +func Launch(s string) { + var cfg Config + _ = json.Unmarshal([]byte(s), &cfg) + c := &config.MixedConfig{ + Role: config.RoleClient, + DNS: &dns.DNS{ + Server: cfg.DNS, + }, + CAs: []string{ + cfg.CA, + }, + LogMode: logger.Mode(cfg.Log), + Client: client.Client{ + ServerAddr: cfg.ServerAddr, + Host: cfg.Host, + UUID: cfg.Uuid, + ListenSocks: cfg.ListenSocks, + ListenHttp: cfg.ListenHttp, + Mux: uint8(cfg.Mux), + EnableTLS: cfg.Tls, + }, + Server: server.Server{ + Path: cfg.Path, + Buffer: uint16(cfg.Buffer), + }, + } + api.Launch(c) +} + +func LaunchFromFile(path string) { + api.LaunchFromFile(path) +} + +func LaunchFromString(c string) { + api.LaunchFromString(c) +} + +func Stop() { + api.Stop() +}