Skip to content

Commit

Permalink
Revert "refactor: Swap out encoding/json for agent protocol with CBOR"
Browse files Browse the repository at this point in the history
This reverts commit de17a57.
  • Loading branch information
pojntfx committed Dec 22, 2024
1 parent de17a57 commit 0ec9815
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 72 deletions.
7 changes: 3 additions & 4 deletions cmd/drafter-forwarder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ package main

import (
"context"
"encoding/json"
"flag"
"log"
"net"
"os"
"os/signal"

"github.com/fxamacker/cbor/v2"

"github.com/loopholelabs/drafter/pkg/forwarder"
"github.com/loopholelabs/goroutine-manager/pkg/manager"
)

func main() {
rawHostVethCIDR := flag.String("host-veth-cidr", "10.0.8.0/22", "CIDR for the veths outside the namespace")

defaultPortForwards, err := cbor.Marshal([]forwarder.PortForward{
defaultPortForwards, err := json.Marshal([]forwarder.PortForward{
{
Netns: "ark0",
InternalPort: "6379",
Expand All @@ -35,7 +34,7 @@ func main() {
flag.Parse()

var portForwards []forwarder.PortForward
if err := cbor.Unmarshal([]byte(*rawPortForwards), &portForwards); err != nil {
if err := json.Unmarshal([]byte(*rawPortForwards), &portForwards); err != nil {
panic(err)
}

Expand Down
7 changes: 3 additions & 4 deletions cmd/drafter-mounter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/json"
"errors"
"flag"
"io"
Expand All @@ -14,8 +15,6 @@ import (
"sync"
"time"

"github.com/fxamacker/cbor/v2"

"github.com/loopholelabs/drafter/pkg/mounter"
"github.com/loopholelabs/drafter/pkg/packager"
"github.com/loopholelabs/goroutine-manager/pkg/manager"
Expand All @@ -42,7 +41,7 @@ type CompositeDevices struct {
}

func main() {
defaultDevices, err := cbor.Marshal([]CompositeDevices{
defaultDevices, err := json.Marshal([]CompositeDevices{
{
Name: packager.StateName,

Expand Down Expand Up @@ -178,7 +177,7 @@ func main() {
defer cancel()

var devices []CompositeDevices
if err := cbor.Unmarshal([]byte(*rawDevices), &devices); err != nil {
if err := json.Unmarshal([]byte(*rawDevices), &devices); err != nil {
panic(err)
}

Expand Down
7 changes: 3 additions & 4 deletions cmd/drafter-packager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ package main

import (
"context"
"encoding/json"
"flag"
"log"
"os"
"os/signal"
"path/filepath"

"github.com/fxamacker/cbor/v2"

"github.com/loopholelabs/drafter/pkg/packager"
"github.com/loopholelabs/goroutine-manager/pkg/manager"
)

func main() {
defaultDevices, err := cbor.Marshal([]packager.PackagerDevice{
defaultDevices, err := json.Marshal([]packager.PackagerDevice{
{
Name: packager.StateName,
Path: filepath.Join("out", "package", "state.bin"),
Expand Down Expand Up @@ -57,7 +56,7 @@ func main() {
flag.Parse()

var devices []packager.PackagerDevice
if err := cbor.Unmarshal([]byte(*rawDevices), &devices); err != nil {
if err := json.Unmarshal([]byte(*rawDevices), &devices); err != nil {
panic(err)
}

Expand Down
7 changes: 3 additions & 4 deletions cmd/drafter-peer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/json"
"errors"
"flag"
"io"
Expand All @@ -15,8 +16,6 @@ import (
"sync"
"time"

"github.com/fxamacker/cbor/v2"

"github.com/loopholelabs/drafter/pkg/ipc"
"github.com/loopholelabs/drafter/pkg/mounter"
"github.com/loopholelabs/drafter/pkg/packager"
Expand Down Expand Up @@ -71,7 +70,7 @@ func main() {
experimentalMapPrivateStateOutput := flag.String("experimental-map-private-state-output", "", "(Experimental) Path to write the local changes to the shared state to (leave empty to write back to device directly) (ignored unless --experimental-map-private)")
experimentalMapPrivateMemoryOutput := flag.String("experimental-map-private-memory-output", "", "(Experimental) Path to write the local changes to the shared memory to (leave empty to write back to device directly) (ignored unless --experimental-map-private)")

defaultDevices, err := cbor.Marshal([]CompositeDevices{
defaultDevices, err := json.Marshal([]CompositeDevices{
{
Name: packager.StateName,

Expand Down Expand Up @@ -213,7 +212,7 @@ func main() {
defer cancel()

var devices []CompositeDevices
if err := cbor.Unmarshal([]byte(*rawDevices), &devices); err != nil {
if err := json.Unmarshal([]byte(*rawDevices), &devices); err != nil {
panic(err)
}

Expand Down
7 changes: 3 additions & 4 deletions cmd/drafter-registry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/json"
"flag"
"fmt"
"io"
Expand All @@ -11,15 +12,13 @@ import (
"os/signal"
"path/filepath"

"github.com/fxamacker/cbor/v2"

"github.com/loopholelabs/drafter/pkg/packager"
"github.com/loopholelabs/drafter/pkg/registry"
"github.com/loopholelabs/goroutine-manager/pkg/manager"
)

func main() {
defaultDevices, err := cbor.Marshal([]registry.RegistryDevice{
defaultDevices, err := json.Marshal([]registry.RegistryDevice{
{
Name: packager.StateName,
Input: filepath.Join("out", "package", "state.bin"),
Expand Down Expand Up @@ -70,7 +69,7 @@ func main() {
defer cancel()

var devices []registry.RegistryDevice
if err := cbor.Unmarshal([]byte(*rawDevices), &devices); err != nil {
if err := json.Unmarshal([]byte(*rawDevices), &devices); err != nil {
panic(err)
}

Expand Down
9 changes: 4 additions & 5 deletions cmd/drafter-runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/json"
"flag"
"log"
"os"
Expand All @@ -12,8 +13,6 @@ import (
"syscall"
"time"

"github.com/fxamacker/cbor/v2"

"github.com/loopholelabs/drafter/pkg/ipc"
"github.com/loopholelabs/drafter/pkg/packager"
"github.com/loopholelabs/drafter/pkg/peer"
Expand All @@ -31,7 +30,7 @@ type SharableDevice struct {
}

func main() {
defaultDevices, err := cbor.Marshal([]SharableDevice{
defaultDevices, err := json.Marshal([]SharableDevice{
{
Name: packager.StateName,
Path: filepath.Join("out", "package", "state.bin"),
Expand Down Expand Up @@ -101,7 +100,7 @@ func main() {
defer cancel()

var devices []SharableDevice
if err := cbor.Unmarshal([]byte(*rawDevices), &devices); err != nil {
if err := json.Unmarshal([]byte(*rawDevices), &devices); err != nil {
panic(err)
}

Expand Down Expand Up @@ -135,7 +134,7 @@ func main() {
defer configFile.Close()

var packageConfig snapshotter.PackageConfiguration
if err := cbor.NewDecoder(configFile).Decode(&packageConfig); err != nil {
if err := json.NewDecoder(configFile).Decode(&packageConfig); err != nil {
panic(err)
}

Expand Down
7 changes: 3 additions & 4 deletions cmd/drafter-snapshotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/json"
"flag"
"log"
"os"
Expand All @@ -10,8 +11,6 @@ import (
"path/filepath"
"time"

"github.com/fxamacker/cbor/v2"

"github.com/loopholelabs/drafter/pkg/packager"
"github.com/loopholelabs/drafter/pkg/snapshotter"
"github.com/loopholelabs/goroutine-manager/pkg/manager"
Expand Down Expand Up @@ -41,7 +40,7 @@ func main() {
livenessVSockPort := flag.Int("liveness-vsock-port", 25, "Liveness VSock port")
agentVSockPort := flag.Int("agent-vsock-port", 26, "Agent VSock port")

defaultDevices, err := cbor.Marshal([]snapshotter.SnapshotDevice{
defaultDevices, err := json.Marshal([]snapshotter.SnapshotDevice{
{
Name: packager.StateName,
Output: filepath.Join("out", "package", "state.bin"),
Expand Down Expand Up @@ -90,7 +89,7 @@ func main() {
defer cancel()

var devices []snapshotter.SnapshotDevice
if err := cbor.Unmarshal([]byte(*rawDevices), &devices); err != nil {
if err := json.Unmarshal([]byte(*rawDevices), &devices); err != nil {
panic(err)
}

Expand Down
7 changes: 3 additions & 4 deletions cmd/drafter-terminator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/json"
"flag"
"io"
"log"
Expand All @@ -10,15 +11,13 @@ import (
"os/signal"
"path/filepath"

"github.com/fxamacker/cbor/v2"

"github.com/loopholelabs/drafter/pkg/packager"
"github.com/loopholelabs/drafter/pkg/terminator"
"github.com/loopholelabs/goroutine-manager/pkg/manager"
)

func main() {
defaultDevices, err := cbor.Marshal([]terminator.TerminatorDevice{
defaultDevices, err := json.Marshal([]terminator.TerminatorDevice{
{
Name: packager.StateName,
Output: filepath.Join("out", "package", "state.bin"),
Expand Down Expand Up @@ -61,7 +60,7 @@ func main() {
defer cancel()

var devices []terminator.TerminatorDevice
if err := cbor.Unmarshal([]byte(*rawDevices), &devices); err != nil {
if err := json.Unmarshal([]byte(*rawDevices), &devices); err != nil {
panic(err)
}

Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ toolchain go1.23.2
require (
github.com/coreos/go-iptables v0.8.0
github.com/freddierice/go-losetup/v2 v2.0.1
github.com/fxamacker/cbor/v2 v2.7.0
github.com/klauspost/compress v1.17.11
github.com/lithammer/shortuuid/v4 v4.2.0
github.com/loopholelabs/goroutine-manager v0.1.1
Expand Down Expand Up @@ -52,7 +51,6 @@ require (
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/redis/go-redis/v9 v9.7.0 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/freddierice/go-losetup/v2 v2.0.1 h1:wPDx/Elu9nDV8y/CvIbEDz5Xi5Zo80y4h7MKbi3XaAI=
github.com/freddierice/go-losetup/v2 v2.0.1/go.mod h1:TEyBrvlOelsPEhfWD5rutNXDmUszBXuFnwT1kIQF4J8=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
Expand Down Expand Up @@ -193,8 +191,6 @@ github.com/vishvananda/netlink v1.3.0/go.mod h1:i6NetklAujEcC6fK0JPjT8qSwWyO0HLn
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zdEY=
github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
Expand Down
5 changes: 2 additions & 3 deletions internal/firecracker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package firecracker
import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"net/http"
"path"

"github.com/fxamacker/cbor/v2"

v1 "github.com/loopholelabs/drafter/internal/api/http/firecracker/v1"
)

Expand Down Expand Up @@ -41,7 +40,7 @@ const (
)

func submitJSON(ctx context.Context, method string, client *http.Client, body any, resource string) error {
p, err := cbor.Marshal(body)
p, err := json.Marshal(body)
if err != nil {
return errors.Join(ErrCouldNotMarshalJSON, err)
}
Expand Down
Loading

0 comments on commit 0ec9815

Please sign in to comment.