Skip to content
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

add dmsghttp feature #131

Merged
merged 13 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "{build}"

stack: go 1.16.7
stack: go 1.16.10

environment:
matrix:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ This is a note for developers about the recommended tags to keep track of the ch

Dates must be YEAR-MONTH-DAY
-->
## [0.3.1] - 2021-06-30
### Changed

- Updated Skywire to `v0.4.2`.

### Fixed
- Fixed `make build-skybian-img`.
- Updated `orange pi prime` and `orange pi 3` OS image urls.

## [0.2.1] - 2021-03-24

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Golang 1.13+ is requred.
**Additional dependencies for building Skybian base image:**

```
rsync wget 7z cut awk sha256sum gzip tar e2fsck losetup resize2fs truncate sfdisk qemu-aarch64-static qemu-arm-static go
rsync wget 7z cut awk sha256sum gzip tar e2fsck losetup resize2fs truncate sfdisk xorg-dev qemu-aarch64-static qemu-arm-static go
```

For Debian-based linux distributions, you can install these via:
```bash
$ sudo apt update && sudo apt install -y p7zip-full qemu-user-static build-essential crossbuild-essential-arm64
$ sudo apt update && sudo apt install -y p7zip-full qemu-user-static build-essential crossbuild-essential-arm64 xorg-dev
```

On Arch-based distributions, to satisfy the `qemu-aarch64-static` dependency, one can install the `qemu-arm-static` AUR package.
Expand Down Expand Up @@ -90,6 +90,7 @@ Values of the boot parameters are separated by `0x1F` characters. The values are
- `GW`: The gateway IP address. Only IPv4 compatible addresses are supported.
- `SS`: The passcode for the `skysocks` app (Only valid if `MD=0x01` - Visor).
- `HVS`: Delegated hypervisor public keys. (Only valid of `MD=0x01` - Visor).
- `DH`: DMSGHTTP Servers List. (Only available if dmsghttp checked and selected related json file).

These values can be written by the `skyimager-gui` (provided in this repo) with user-provided options.

Expand Down
2 changes: 2 additions & 0 deletions build.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# version must always start with "v" like: v0.1.45-rc

VERSION=v0.4.0

# This must match the tags in the github repository

# loading the actual path
Expand All @@ -25,6 +26,7 @@ RASPBIAN_ARM64_DOWNLOAD_URL="https://downloads.raspberrypi.org/raspios_lite_arm6

# Skywire release download for OS running on destination skyminer
SKYWIRE_VERSION=v0.5.0

SKYWIRE_ARM64_DOWNLOAD_URL="https://github.com/skycoin/skywire/releases/download/$SKYWIRE_VERSION/skywire-$SKYWIRE_VERSION-linux-arm64.tar.gz"
SKYWIRE_ARM_DOWNLOAD_URL="https://github.com/skycoin/skywire/releases/download/$SKYWIRE_VERSION/skywire-$SKYWIRE_VERSION-linux-arm.tar.gz"
# Offset and sector size of the Armbian image for rootfs (found automatically if not set)
Expand Down
13 changes: 13 additions & 0 deletions dmsghttp-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"dmsg_servers": [
"ip:port",
"ip:port",
"ip:port"
],
"dmsg_discovery": "dmsg://pk:port",
"transport_discovery": "dmsg://pk:port",
"address_resolver": "dmsg://pk:port",
"route_finder": "dmsg://pk:port",
"uptime_tracker": "dmsg://pk:port",
"service_discovery": "dmsg://pk:port"
}
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ go 1.16

require (
fyne.io/fyne/v2 v2.1.0
github.com/fyne-io/fyne-cross v1.1.2 // indirect
github.com/google/go-github v17.0.0+incompatible
github.com/mholt/archiver v3.1.1+incompatible
github.com/rakyll/statik v0.1.7
github.com/sirupsen/logrus v1.8.1
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/skycoin/dmsg v0.0.0-20210920120709-00d42a07e45a
github.com/skycoin/dmsg v0.0.0-20211007145032-962409e5845f
github.com/skycoin/skycoin v0.27.1
github.com/skycoin/skywire v0.5.0-rc1.0.20210928121629-42a9d6fc03f1
github.com/skycoin/skywire v0.5.2-0.20211117112105-25406ce9ef63
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
)
Expand Down
26 changes: 8 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ github.com/AudriusButkevicius/pfilter v0.0.0-20210515103320-4b4b86609d51/go.mod
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9 h1:1ltqoej5GtaWF8jaiA49HwsZD459jqm9YFz9ZtMFpQA=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
Expand Down Expand Up @@ -51,8 +50,6 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.10/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.15/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -70,10 +67,6 @@ github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3/go.mod h1:CzM2G82Q9BDUv
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fyne-io/fyne-cross v1.1.1 h1:loYNaPB7ty43owmPzyDH5jxuEPfBUx+MZ0K41LenqJc=
github.com/fyne-io/fyne-cross v1.1.1/go.mod h1:rFwn/M7pkAVZkQTndaD3i5DbZ5oTMJIEWDCF2w7d60Q=
github.com/fyne-io/fyne-cross v1.1.2 h1:LezY9vF5gLGpNoSGzB5EP0MU9D/b3F73NKafTZZnSLw=
github.com/fyne-io/fyne-cross v1.1.2/go.mod h1:rFwn/M7pkAVZkQTndaD3i5DbZ5oTMJIEWDCF2w7d60Q=
github.com/gen2brain/dlgs v0.0.0-20210609125024-bf6c92aaa984/go.mod h1:/eFcjDXaU2THSOOqLxOPETIbHETnamk8FA/hMjhg/gU=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY=
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7/go.mod h1:l+xpFBrCtDLpK9qNjxs+cHU6+BAdlBaxHqikB6Lku3A=
Expand Down Expand Up @@ -210,9 +203,8 @@ github.com/marten-seemann/qtls-go1-15 v0.1.4 h1:RehYMOyRW8hPVEja1KBVsFVNSm35Jj9M
github.com/marten-seemann/qtls-go1-15 v0.1.4/go.mod h1:GyFwywLKkRt+6mfU99csTEY1joMZz5vmB1WNZH3P81I=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
Expand Down Expand Up @@ -312,16 +304,15 @@ github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA=
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
github.com/skycoin/dmsg v0.0.0-20210915195912-2f9b055f39fe/go.mod h1:qs+tELY7/gHRHqCK0iPp62BuYlu10OcV5zN0lpa1Scc=
github.com/skycoin/dmsg v0.0.0-20210920120709-00d42a07e45a h1:nwPsyPz33ti8ZcsJWWsbnjOZw2w2W8U2JpSQ26KHLps=
github.com/skycoin/dmsg v0.0.0-20210920120709-00d42a07e45a/go.mod h1:p9RQVoY18Rpi5mrbIfE55z7XcKTscIUiNh8nv1ou1/8=
github.com/skycoin/dmsg v0.0.0-20211007145032-962409e5845f h1:0/PJaqsGvkfuf4I/Jg2ayQq0AJg5qhIhK4YzevX72Bg=
github.com/skycoin/dmsg v0.0.0-20211007145032-962409e5845f/go.mod h1:p9RQVoY18Rpi5mrbIfE55z7XcKTscIUiNh8nv1ou1/8=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0duwyG+7WliWz5u9kgk1h5MnLuA=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:UXghlricA7J3aRD/k7p/zBObQfmBawwCxIVPVjz2Q3o=
github.com/skycoin/skycoin v0.26.0/go.mod h1:78nHjQzd8KG0jJJVL/j0xMmrihXi70ti63fh8vXScJw=
github.com/skycoin/skycoin v0.27.1 h1:HatxsRwVSPaV4qxH6290xPBmkH/HgiuAoY2qC+e8C9I=
github.com/skycoin/skycoin v0.27.1/go.mod h1:78nHjQzd8KG0jJJVL/j0xMmrihXi70ti63fh8vXScJw=
github.com/skycoin/skywire v0.5.0-rc1.0.20210928121629-42a9d6fc03f1 h1:6rqD0Q1TgiWTGF99C7lUbrComNgIBez4/tqAP2b8Mew=
github.com/skycoin/skywire v0.5.0-rc1.0.20210928121629-42a9d6fc03f1/go.mod h1:mgDMpaOFkMPt8gbCTI5VniyBsczUkvcDWdLhXRqG+Zs=
github.com/skycoin/skywire v0.5.2-0.20211117112105-25406ce9ef63 h1:kHDwJV4O0ggN+8EeBKetxYwX9DNhjjNsp2tB+uU+esk=
github.com/skycoin/skywire v0.5.2-0.20211117112105-25406ce9ef63/go.mod h1:H35tSOwurUtc25Pm2lr5vLQIm8tzrfJV92mSUb2dXvY=
github.com/skycoin/yamux v0.0.0-20200803175205-571ceb89da9f h1:A5dEM1OE9YhN3LciZU9qPjo7fJ46JeHNi3JCroDkK0Y=
github.com/skycoin/yamux v0.0.0-20200803175205-571ceb89da9f/go.mod h1:48cleOxgkiLbgv322LOg2Vrxtu180Mb8GG1HbuhmFYM=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down Expand Up @@ -412,9 +403,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
Expand Down Expand Up @@ -492,9 +482,9 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210217105451-b926d437f341/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210608053332-aa57babbf139/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210406210042-72f3dc4e9b72/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
Expand Down
4 changes: 2 additions & 2 deletions integration/cmd/mock_mbr.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func main() {
switch mode {
case 0:
// Hypervisor
bp, err = boot.MakeHypervisorParams(gwIP, sk, "", "")
bp, err = boot.MakeHypervisorParams(gwIP, sk, "", "", "")
case 1:
// Visor.
bp, err = boot.MakeVisorParams(gwIP, gwIP, sk, makeHvPKs(), "123456", "", "")
bp, err = boot.MakeVisorParams(gwIP, gwIP, sk, makeHvPKs(), "123456", "", "", "")
default:
err = errors.New("invalid mode")
}
Expand Down
77 changes: 66 additions & 11 deletions pkg/boot/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package boot

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"strings"
Expand Down Expand Up @@ -62,6 +64,8 @@ const (
SocksPassEnv = "SS"
WifiNameEnv = "WFN"
WifiPassEnv = "WFP"
// DSMGHTTP
DMSGHTTPEnv = "DH"
)

// Modes.
Expand Down Expand Up @@ -118,13 +122,26 @@ type Params struct {
LocalPK cipher.PubKey `json:"local_pk"` // Not actually encoded to bps.
LocalSK cipher.SecKey `json:"local_sk"`

// only on dmsghttp
DMSGHTTP string `json:"dmsghttp,omitempty"`
mrpalide marked this conversation as resolved.
Show resolved Hide resolved

// only valid if mode == "0x00" (hypervisor)
HypervisorPKs cipher.PubKeys `json:"hypervisor_pks,omitempty"`
SkysocksPasscode string `json:"skysocks_passcode,omitempty"`
}

type dmsgHTTPServers struct {
ersonp marked this conversation as resolved.
Show resolved Hide resolved
DMSGServers []string `json:"dmsg_servers"`
DMSGDiscovery string `json:"dmsg_discovery"`
TransportDiscovery string `json:"transport_discovery"`
AddressResolver string `json:"address_resolver"`
RouteFinder string `json:"route_finder"`
UptimeTracker string `json:"uptime_tracker"`
ServiceDiscovery string `json:"service_discovery"`
}

// MakeHypervisorParams is a convenience function for creating boot parameters for a hypervisor.
func MakeHypervisorParams(gwIP net.IP, sk cipher.SecKey, wifiName, wifiPass string) (Params, error) {
func MakeHypervisorParams(gwIP net.IP, sk cipher.SecKey, wifiName, wifiPass, dmsgHTTPPath string) (Params, error) {
pk, err := sk.PubKey()
if err != nil {
return Params{}, err
Expand All @@ -140,6 +157,15 @@ func MakeHypervisorParams(gwIP net.IP, sk cipher.SecKey, wifiName, wifiPass stri
LocalPK: pk,
LocalSK: sk,
}

if len(dmsgHTTPPath) > 0 {
stringData, err := dmsgHTTPHandler(dmsgHTTPPath)
if err != nil {
return Params{}, err
}
params.DMSGHTTP = stringData
}

if wifiName != "" || wifiPass != "" {
params.WifiEndpointName = wifiName
params.WifiEndpointPass = wifiPass
Expand All @@ -150,7 +176,7 @@ func MakeHypervisorParams(gwIP net.IP, sk cipher.SecKey, wifiName, wifiPass stri

// MakeVisorParams is a convenience function for creating boot parameters for a visor.
func MakeVisorParams(prevIP, gwIP net.IP, sk cipher.SecKey, hvPKs []cipher.PubKey,
socksPC string, wifiName, wifiPass string) (Params, error) {
socksPC, wifiName, wifiPass, dmsgHTTPPath string) (Params, error) {
pk, err := sk.PubKey()
if err != nil {
return Params{}, err
Expand All @@ -168,6 +194,15 @@ func MakeVisorParams(prevIP, gwIP net.IP, sk cipher.SecKey, hvPKs []cipher.PubKe
HypervisorPKs: hvPKs,
SkysocksPasscode: socksPC,
}

if len(dmsgHTTPPath) > 0 {
stringData, err := dmsgHTTPHandler(dmsgHTTPPath)
if err != nil {
return Params{}, err
}
params.DMSGHTTP = stringData
}

if wifiName != "" || wifiPass != "" {
params.WifiEndpointName = wifiName
params.WifiEndpointPass = wifiPass
Expand All @@ -176,6 +211,20 @@ func MakeVisorParams(prevIP, gwIP net.IP, sk cipher.SecKey, hvPKs []cipher.PubKe
return params, err
}

func dmsgHTTPHandler(dmsgHTTPPath string) (string, error) {
var dmsgHTTPServersData dmsgHTTPServers
serversListJSON, err := ioutil.ReadFile(dmsgHTTPPath)
if err != nil {
return "", err
}
err = json.Unmarshal(serversListJSON, &dmsgHTTPServersData)
if err != nil {
return "", err
}
dmsgHTTPJSON, _ := json.Marshal(dmsgHTTPServersData)
return string(dmsgHTTPJSON), nil
}

// MakeParams is a convenience function for creating a slice of boot parameters.
func MakeParams(mode Mode, lIP, gwIP, lSK string, hvPKs ...string) (Params, error) {
var bp Params
Expand Down Expand Up @@ -265,6 +314,12 @@ func (bp Params) PrintEnvs(w io.Writer) error {
return err
}
}
// DMSGHTTP
if len(bp.DMSGHTTP) > 0 {
if err := PrintEnv(w, DMSGHTTPEnv, bp.DMSGHTTP); err != nil {
return err
}
}
return nil
}

Expand All @@ -277,7 +332,7 @@ func (bp Params) PrintEnvs(w io.Writer) error {
func (bp Params) Encode() ([]byte, error) {
keys := bp.LocalSK[:]
toEncode := [][]byte{{byte(bp.Mode)}, bp.LocalIP, bp.GatewayIP,
[]byte(bp.SkysocksPasscode), []byte(bp.WifiEndpointName), []byte(bp.WifiEndpointPass)}
[]byte(bp.SkysocksPasscode), []byte(bp.WifiEndpointName), []byte(bp.WifiEndpointPass), []byte(bp.DMSGHTTP)}
for _, hvPK := range bp.HypervisorPKs {
keys = append(keys, hvPK[:]...)
}
Expand All @@ -294,21 +349,21 @@ func (bp Params) Encode() ([]byte, error) {

// Decode decodes the boot parameters from the given raw bytes.
func (bp *Params) Decode(raw []byte) error {
split := bytes.SplitN(raw, []byte{sep}, 7)
// 5 for a regular config, 7 for wifi-enabled config
if len(split) != 7 {
split := bytes.SplitN(raw, []byte{sep}, 8)

if len(split) != 8 {
return ErrCannotReadParams
}

bp.Mode, bp.LocalIP, bp.GatewayIP, bp.SkysocksPasscode =
Mode(split[0][0]), split[1], split[2], string(split[3])

if len(split) == 7 {
bp.WifiEndpointName = string(split[4])
bp.WifiEndpointPass = string(split[5])
}
bp.WifiEndpointName = string(split[4])
bp.WifiEndpointPass = string(split[5])

bp.DMSGHTTP = string(split[6])

keys := split[6]
keys := split[7]
keys = keys[copy(bp.LocalSK[:], keys):]
for {
var pk cipher.PubKey
Expand Down
Loading