Skip to content

Commit

Permalink
feat: default main on port 5050 if tcpapps unconfigured (#264)
Browse files Browse the repository at this point in the history
* feat: automatically assign main port

* feat: default app on port 5555

* fix: default to port `5050`

* doc: move to using port 5050
  • Loading branch information
Devdutt Shenoi authored Aug 5, 2023
1 parent f2f6f46 commit c9cd830
Show file tree
Hide file tree
Showing 20 changed files with 485 additions and 470 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ With the help of tunshell, uplink allows you to remotely connect to a device she
You can test sending JSON data to Bytebeam over uplink with the following command while uplink is active

```sh
nc localhost 5555
nc localhost 5050
{ "stream": "can", "sequence": 1, "timestamp": 12345, "data": 100 }
{ "stream": "can", "sequence": 1, "timestamp": 12345, "data": 100 }
{ "stream": "can", "sequence": 1, "timestamp": 12345, "data": 100 }
Expand Down
4 changes: 2 additions & 2 deletions configs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ network_timeout = 30
# - actions: A list of actions that uplink can forward to the app,
# with configurable timeouts
[tcpapps.1]
port = 5555
port = 5050
actions = [{ name = "install_update" }, { name = "load_file" }]

[tcpapps.2]
port = 5556
port = 6060
actions = []

# Metrics configurations are available for serializer and streams. By default
Expand Down
2 changes: 1 addition & 1 deletion configs/simulator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ action_redirections = { "update_firmware" = "install_update", "send_file" = "loa
persistence_path = "/tmp/uplink"

[tcpapps.1]
port = 5555
port = 5050
2 changes: 1 addition & 1 deletion configs/stress.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ processes = [{ name = "echo" }]
action_redirections = { "update_firmware" = "install_update", "send_file" = "load_file" }

[tcpapps.1]
port = 5555
port = 5050
actions = [{ name = "install_update" }, { name = "load_file" }]

[persistence]
Expand Down
10 changes: 5 additions & 5 deletions docs/apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
uplink is a service that runs in the background and connects user applications to the bytebeam platform.

## Configuring uplink
Applications can connect to the uplink service over TCP to send and receive JSON data, and for this uplink has to expose a TCP port per application. The following example configuration describes to uplink that two applications require it to expose the ports 5555 and 6666, where one of them also expects to receive `install_firmware` actions:
Applications can connect to the uplink service over TCP to send and receive JSON data, and for this uplink has to expose a TCP port per application. The following example configuration describes to uplink that two applications require it to expose the ports 5050 and 6060, where one of them also expects to receive `install_firmware` actions:
```
[tcpapps.main_app]
port = 5555
port = 5050
[tcpapps.ota_installer]
port = 5555
port = 6060
actions = [{ name = "install_firmware" }]
```
NOTE: Only one client can connect to a TCP port at a time. If a second client attempts to connect to a port which is already occupied, the first client will be disconnected from uplink.
Expand Down Expand Up @@ -77,7 +77,7 @@ An example success response to an action with the id `"123"`, would look like:
> **NOTE:** There is a timeout mechanism which on being triggered will send a ***Failed*** response to platform and stop forwarding any *Progress* responses from the connected applications. In order to not trigger this timeout, an application must send a ***Failed*** or ***Completed*** response before the action timeout. Once an action has timedout, a failure response is sent and all it's future responses are dropped. Action timeouts can be configured per action when setting up uplink, as follows:
> ```
> [tcpapps.main_app]
> port = 5555
> port = 5050
> actions = [{ name = "abc", timeout = 300 }] # Allow the connected app to send responses for action abc upto 5 minutes from receive, send a failure response and drop all responses afterwards if not yet completed.
> ```
Expand All @@ -86,7 +86,7 @@ We have provided examples written in python and golang to demonstrate how you ca
1. Ensure uplink is running on the device, connected to relevant broker and using the following config:
```toml
[tcpapps.main_app]
port = 5555
port = 5050
actions = [{ name = "update_firmware" }, { name = "reboot" }, { name = "update_config" }]
```
2. Run the python/golang examples
Expand Down
2 changes: 1 addition & 1 deletion examples/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Action struct {

func main() {
// Connect to uplink via bridge port
c, err := net.Dial("tcp", "localhost:5555")
c, err := net.Dial("tcp", "localhost:5050")
if err != nil {
fmt.Println(err)
return
Expand Down
2 changes: 1 addition & 1 deletion examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import threading

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 5555))
s.connect(("localhost", 5050))

# Converts JSON data received over TCP into a python dictionary
def recv_action(s):
Expand Down
2 changes: 1 addition & 1 deletion examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::thread;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

fn main() -> Result<()> {
let mut stream = TcpStream::connect("localhost:5555").expect("couldn't connect to server");
let mut stream = TcpStream::connect("localhost:5050").expect("couldn't connect to server");
let stream_clone = stream.try_clone().expect("clone failed...");
println!("Connected to the server!");

Expand Down
2 changes: 1 addition & 1 deletion examples/rpi/updates/app_update/app_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# COPROC[1] is the stdin for netcat
# COPROC[0] is the stdout of netcat
# By echoing to the stdin of nc, we write to the port 5555
# By echoing to the stdin of nc, we write to the port 5050

PORT=$2
APP=$3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# COPROC[1] is the stdin for netcat
# COPROC[0] is the stdout of netcat
# By echoing to the stdin of nc, we write to the port 5555
# By echoing to the stdin of nc, we write to the port 5050

PORT=$2
APP=$3
Expand Down
2 changes: 1 addition & 1 deletion examples/rpi/updates/deb_update/deb_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## This script is used for deb package updates
# COPROC[1] is the stdin for netcat
# COPROC[0] is the stdout of netcat
# By echoing to the stdin of nc, we write to the port 5555
# By echoing to the stdin of nc, we write to the port 5050
dpkg -i $3/*.deb $4

# To extract to the custom location
Expand Down
2 changes: 1 addition & 1 deletion examples/rpi/updates/rootfs_update/rootfs_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# COPROC[1] is the stdin for netcat
# COPROC[0] is the stdout of netcat
# By echoing to the stdin of nc, we write to the port 5555
# By echoing to the stdin of nc, we write to the port 5050

PORT=$2
coproc nc localhost $PORT
Expand Down
2 changes: 1 addition & 1 deletion scripts/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import subprocess

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 5555))
s.connect(("localhost", 5050))

# Converts JSON data received over TCP into a python dictionary
def recv_action(s):
Expand Down
4 changes: 2 additions & 2 deletions scripts/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
persistence_path = "/tmp/uplink"
action_redirections={update_firmware="install_firmware"}
[tcpapps.1]
port=5555
port=5050
actions=[{name="reboot"}]

[downloader]
Expand All @@ -15,7 +15,7 @@ port=3333
[ota_installer]
path="/tmp/uplink/installer"
actions=[{name="install_firmware", timeout=610}]
uplink_port=5555
uplink_port=5050

[logging]
tags=["sshd", "systemd"]
Expand Down
2 changes: 1 addition & 1 deletion scripts/startup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
root_part=`awk -F"root=" '{ print $NF; }' /proc/cmdline | cut -d" " -f1`

coproc nc localhost 5555
coproc nc localhost 5050

if [ -f "/mnt/download/action_id" ]
then
Expand Down
4 changes: 2 additions & 2 deletions scripts/uplink.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

action_redirections={update_firmware="install_firmware"}
[tcpapps.1]
port=5555
port=5050

[downloader]
path="/tmp/uplink/download"
Expand All @@ -10,4 +10,4 @@ actions=[{name="update_firmware", timeout=310}, {name="send_file"}]
[ota_installer]
path="/tmp/uplink/installer"
actions=[{name="install_firmware", timeout=310}]
uplink_port=5555
uplink_port=5050
Loading

0 comments on commit c9cd830

Please sign in to comment.