-
Notifications
You must be signed in to change notification settings - Fork 13
feat: emulator branch changes #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,14 +10,35 @@ All version numbers are controlled by `VERSION` at root level, no need to change | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| For things work properly , be sure to follow build methods documented in [Build.md](Build.md) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ## Emulator support | ||||||||||||||||||||||||||||||||||
| ## Launch Parameters | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ### HTTP Server Port Configuration | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| OneKey bridge runs an HTTP server on port 21320 by default. You can change this port using the `-p` parameter. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| **Examples:** | ||||||||||||||||||||||||||||||||||
| - `./onekeyd` - Uses default port 21320 | ||||||||||||||||||||||||||||||||||
| - `./onekeyd -p 21325` - Uses port 21325 | ||||||||||||||||||||||||||||||||||
| - `./onekeyd -p 21321` - Uses port 21321 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| This is useful when: | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Fix article and punctuation -OneKey bridge runs an HTTP server on port 21320 by default. You can change this port using the `-p` parameter.
+OneKey Bridge runs an HTTP server on port 21320 by default; you can change the port with the `-p` parameter.📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[uncategorized] ~17-~17: Possible missing comma found. (AI_HYDRA_LEO_MISSING_COMMA) 🪛 markdownlint-cli2 (0.17.2)20-20: Lists should be surrounded by blank lines (MD032, blanks-around-lists) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| - Running multiple bridge instances simultaneously | ||||||||||||||||||||||||||||||||||
| - Port 21320 is already in use by another application | ||||||||||||||||||||||||||||||||||
| - You need to use a specific port for network configuration | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ### Emulator Support | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| OneKey bridge has emulator support, but it's disabled by default. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| To enable emulator support, launch with `-e` parameter followed by port, for example `./onekeyd -e 21324` | ||||||||||||||||||||||||||||||||||
| To enable emulator support, launch with `-e` parameter followed by port, for example `./onekeyd -e 54935` | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| To disable all USB in order to run on some virtual environments,launch with `-u=false` parameter, for example `./onekeyd -u=false` | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| **Combined Examples:** | ||||||||||||||||||||||||||||||||||
| - `./onekeyd -p 21325 -e 54935` - HTTP server on port 21325, emulator on port 54935 | ||||||||||||||||||||||||||||||||||
| - `./onekeyd -p 21321 -u=false` - HTTP server on port 21321, USB disabled | ||||||||||||||||||||||||||||||||||
| - `./onekeyd -p 21321 -e 54935 -u=false` - HTTP server on port 21321,emulator on port 54935, USB disabled | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| If you want change default launch options, you may have to change service accordingly | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ## Edit Default Service Launch Options | ||||||||||||||||||||||||||||||||||
|
|
@@ -30,7 +51,7 @@ On Windows, open `shell:startup` folder, then edit the `OneKey Bridge.lnk` file | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ## API documentation | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| `onekey-bridge` starts a HTTP server on `http://localhost:21320`. AJAX calls are only enabled from onekey.so subdomains. | ||||||||||||||||||||||||||||||||||
| `onekey-bridge` starts a HTTP server on `http://localhost:21320` by default. The port can be configured using the `-p` parameter (see Launch Parameters section above). AJAX calls are only enabled from onekey.so subdomains. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Server supports following API calls: | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -51,9 +72,9 @@ OneKey Bridge has support for debug link. | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| To support an emulator with debug link, run | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| `./onekeyd -ed 21324:21320 -u=false` | ||||||||||||||||||||||||||||||||||
| `./onekeyd -ed 54935:21320 -u=false` | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| this will detect emulator debug link on port 21320, with regular device on 21324. | ||||||||||||||||||||||||||||||||||
| this will detect emulator debug link on port 21320, with regular device on 54935. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| To support WebUSB devices with debug link, no option is needed, just run onekey-bridge. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 2.2.1 | ||
| 2.2.2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,7 @@ func main() { | |
| var verbose bool | ||
| var reset bool | ||
| var versionFlag bool | ||
| var httpPort int | ||
|
|
||
| flag.StringVar(&logfile, "l", "", "Log into a file, rotating after 20MB") | ||
| flag.Var(&ports, "e", "Use UDP port for emulator. Can be repeated for more ports. Example: onekey-go -e 21324 -e 21326") | ||
|
|
@@ -110,6 +111,7 @@ func main() { | |
| flag.BoolVar(&verbose, "v", false, "Write verbose logs to either stderr or logfile") | ||
| flag.BoolVar(&versionFlag, "version", false, "Write version") | ||
| flag.BoolVar(&reset, "r", true, "Reset USB device on session acquiring. Enabled by default (to prevent wrong device states); set to false if you plan to connect to debug link outside of bridge.") | ||
| flag.IntVar(&httpPort, "p", 21320, "HTTP server port. Default is 21320. Example: onekey-go -p 21325") | ||
| flag.Parse() | ||
|
|
||
| if versionFlag { | ||
|
|
@@ -168,7 +170,7 @@ func main() { | |
| longMemoryWriter.Log("Creating core") | ||
| c := core.New(b, longMemoryWriter, allowCancel(), reset) | ||
| longMemoryWriter.Log("Creating HTTP server") | ||
| s, err := server.New(c, stderrWriter, shortMemoryWriter, longMemoryWriter, version) | ||
| s, err := server.New(c, stderrWriter, shortMemoryWriter, longMemoryWriter, version, httpPort) | ||
|
|
||
| if err != nil { | ||
| stderrLogger.Fatalf("https: %s", err) | ||
|
Comment on lines
+173
to
176
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Handle “address already in use” gracefully Right now 🤖 Prompt for AI Agents |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ type Server struct { | |
| serverPrivate | ||
|
|
||
| writer io.Writer | ||
| port int | ||
| } | ||
|
Comment on lines
24
to
26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive)
Leaning toward option 1 for now. 🤖 Prompt for AI Agents |
||
|
|
||
| func New( | ||
|
|
@@ -30,11 +31,12 @@ func New( | |
| shortWriter *memorywriter.MemoryWriter, | ||
| longWriter *memorywriter.MemoryWriter, | ||
| version string, | ||
| httpPort int, | ||
| ) (*Server, error) { | ||
| longWriter.Log("starting") | ||
|
|
||
| https := &http.Server{ | ||
| Addr: "127.0.0.1:21320", | ||
| Addr: fmt.Sprintf("127.0.0.1:%d", httpPort), | ||
| } | ||
|
|
||
| allWriter := io.MultiWriter(stderrWriter, shortWriter, longWriter) | ||
|
|
@@ -43,20 +45,21 @@ func New( | |
| Server: https, | ||
| }, | ||
| writer: allWriter, | ||
| port: httpPort, | ||
| } | ||
|
|
||
| r := mux.NewRouter() | ||
| statusRouter := r.PathPrefix("/status").Subrouter() | ||
| postRouter := r.Methods("POST").Subrouter() | ||
| redirectRouter := r.Methods("GET").Path("/").Subrouter() | ||
|
|
||
| status.ServeStatus(statusRouter, c, version, shortWriter, longWriter) | ||
| status.ServeStatus(statusRouter, c, version, shortWriter, longWriter, httpPort) | ||
| err := api.ServeAPI(postRouter, c, version, longWriter) | ||
| if err != nil { | ||
| panic(err) // only error is an error from originValidator regexp constructor | ||
| } | ||
|
|
||
| status.ServeStatusRedirect(redirectRouter) | ||
| status.ServeStatusRedirect(redirectRouter, httpPort) | ||
|
|
||
| var h http.Handler = r | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package status | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "github.com/OneKeyHQ/onekey-bridge/core" | ||
|
|
@@ -17,35 +18,39 @@ type status struct { | |
| core *core.Core | ||
| version string | ||
| shortMemoryWriter, longMemoryWriter *memorywriter.MemoryWriter | ||
| port int | ||
| } | ||
|
|
||
| const csrfkey = "slk0118h51w2qiw4fhrfyd84f59j81ln" | ||
|
|
||
| func ServeStatusRedirect(r *mux.Router) { | ||
| r.HandleFunc("/", redirect) | ||
| func ServeStatusRedirect(r *mux.Router, httpPort int) { | ||
| r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
| redirect(w, r, httpPort) | ||
| }) | ||
|
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Sanity-check
Add a quick guard: +if httpPort <= 0 || httpPort > 65535 {
+ httpPort = 21320 // fallback or return an error
+}🤖 Prompt for AI Agents |
||
| r.Use(OriginCheck(map[string]string{ | ||
| "": "", | ||
| })) | ||
| } | ||
|
|
||
| func redirect(w http.ResponseWriter, r *http.Request) { | ||
| http.Redirect(w, r, "http://127.0.0.1:21320/status/", http.StatusMovedPermanently) | ||
| func redirect(w http.ResponseWriter, r *http.Request, httpPort int) { | ||
| http.Redirect(w, r, fmt.Sprintf("http://127.0.0.1:%d/status/", httpPort), http.StatusMovedPermanently) | ||
| } | ||
|
Comment on lines
+35
to
37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Use 307 or 308 for redirects that preserve method For local tooling a permanent 301 works, but if clients might POST to -http.Redirect(w, r, fmt.Sprintf("http://127.0.0.1:%d/status/", httpPort), http.StatusMovedPermanently)
+http.Redirect(w, r, fmt.Sprintf("http://127.0.0.1:%d/status/", httpPort), http.StatusTemporaryRedirect)🤖 Prompt for AI Agents |
||
|
|
||
| func ServeStatus(r *mux.Router, c *core.Core, v string, mw, dmw *memorywriter.MemoryWriter) { | ||
| func ServeStatus(r *mux.Router, c *core.Core, v string, mw, dmw *memorywriter.MemoryWriter, httpPort int) { | ||
| status := &status{ | ||
| core: c, | ||
| version: v, | ||
| shortMemoryWriter: mw, | ||
| longMemoryWriter: dmw, | ||
| port: httpPort, | ||
| } | ||
| r.Methods("GET").Path("/").HandlerFunc(status.statusPage) | ||
| r.Methods("POST").Path("/log.gz").HandlerFunc(status.statusGzip) | ||
|
|
||
| r.Use(csrf.Protect([]byte(csrfkey), csrf.Secure(false))) | ||
| r.Use(OriginCheck(map[string]string{ | ||
| "/status/": "", | ||
| "/status/log.gz": "http://127.0.0.1:21320", | ||
| "/status/log.gz": fmt.Sprintf("http://127.0.0.1:%d", httpPort), | ||
| })) | ||
|
Comment on lines
52
to
54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Origin map can be built once
allowed := map[string]string{
"/status/": "",
"/status/log.gz": fmt.Sprintf("http://127.0.0.1:%d", httpPort),
}
r.Use(OriginCheck(allowed))🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Blank line before list to satisfy Markdownlint (MD032)
📝 Committable suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
20-20: Lists should be surrounded by blank lines
null
(MD032, blanks-around-lists)
🤖 Prompt for AI Agents