Skip to content

Commit

Permalink
[pkg/io,wire/perun] Move pkg/io to wire/perunio
Browse files Browse the repository at this point in the history
- pkg/io implements the a custom encoding/decoding logic for sending
  messages on the wire.

- Hence, moving it to a more appropriate path wire/perun.

- Note: persistence/keyvalue also uses the wire/perun encoding for
  storing the channels to the keyvalue store.

Signed-off-by: Manoranjith <[email protected]>
  • Loading branch information
Manoranjith committed Dec 8, 2021
1 parent 39553f9 commit 4392ab6
Show file tree
Hide file tree
Showing 61 changed files with 135 additions and 134 deletions.
2 changes: 1 addition & 1 deletion backend/ethereum/channel/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"perun.network/go-perun/backend/ethereum/bindings/adjudicator"
ethwallet "perun.network/go-perun/backend/ethereum/wallet"
"perun.network/go-perun/channel"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire/perunio"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion backend/ethereum/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
pkgtest "polycry.pt/poly-go/test"

ethwallettest "perun.network/go-perun/backend/ethereum/wallet/test"
"perun.network/go-perun/pkg/io/test"
"perun.network/go-perun/wire/perunio/test"
)

func Test_Asset_GenericMarshaler(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion backend/ethereum/wallet/address_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

"perun.network/go-perun/pkg/io/test"
"perun.network/go-perun/wire/perunio/test"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down
2 changes: 1 addition & 1 deletion backend/ethereum/wallet/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/pkg/errors"

perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire/perunio"
)

// Backend implements the utility interface defined in the wallet package.
Expand Down
4 changes: 2 additions & 2 deletions backend/ethereum/wallet/hd/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
ethwallet "perun.network/go-perun/backend/ethereum/wallet"
"perun.network/go-perun/backend/ethereum/wallet/hd"
ethwallettest "perun.network/go-perun/backend/ethereum/wallet/test"
"perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet/test"
"perun.network/go-perun/wire/perunio"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down Expand Up @@ -123,7 +123,7 @@ func newSetup(t require.TestingT, prng *rand.Rand) (*test.Setup, accounts.Wallet

addressNotInWallet := ethwallettest.NewRandomAddress(prng)
var buff bytes.Buffer
err = io.Encode(&buff, &addressNotInWallet)
err = perunio.Encode(&buff, &addressNotInWallet)
if err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions backend/ethereum/wallet/keystore/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (

ethwallet "perun.network/go-perun/backend/ethereum/wallet"
ethwallettest "perun.network/go-perun/backend/ethereum/wallet/test"
"perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet/test"
"perun.network/go-perun/wire/perunio"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down Expand Up @@ -75,12 +75,12 @@ func TestBackend(t *testing.T) {

buff := bytes.NewReader(s.AddressEncoded)
addr := backend.NewAddress()
err := io.Decode(buff, addr)
err := perunio.Decode(buff, addr)
assert.NoError(t, err, "NewAddress from Bytes should work")

buff = bytes.NewReader([]byte(invalidAddr))
addr = backend.NewAddress()
err = io.Decode(buff, addr)
err = perunio.Decode(buff, addr)
assert.Error(t, err, "Conversion from wrong address should fail")
}

Expand All @@ -89,7 +89,7 @@ func newSetup(t require.TestingT, prng *rand.Rand) *test.Setup {

addressNotInWallet := ethwallettest.NewRandomAddress(prng)
var buff bytes.Buffer
err := io.Encode(&buff, &addressNotInWallet)
err := perunio.Encode(&buff, &addressNotInWallet)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions backend/ethereum/wallet/simple/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
ethwallet "perun.network/go-perun/backend/ethereum/wallet"
"perun.network/go-perun/backend/ethereum/wallet/simple"
ethwallettest "perun.network/go-perun/backend/ethereum/wallet/test"
"perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet/test"
"perun.network/go-perun/wire/perunio"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down Expand Up @@ -104,7 +104,7 @@ func newSetup(t require.TestingT, prng *rand.Rand) (*test.Setup, *simple.Wallet)

addressNotInWallet := ethwallettest.NewRandomAddress(prng)
var buff bytes.Buffer
err = io.Encode(&buff, &addressNotInWallet)
err = perunio.Encode(&buff, &addressNotInWallet)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion backend/sim/channel/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"math/rand"

"perun.network/go-perun/channel"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wire/perunio"
)

// AssetBinaryLen is the length of binary representation of asset, in bytes.
Expand Down
2 changes: 1 addition & 1 deletion backend/sim/channel/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"testing"

"perun.network/go-perun/backend/sim/channel"
"perun.network/go-perun/pkg/io/test"
"perun.network/go-perun/wire/perunio/test"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down
2 changes: 1 addition & 1 deletion backend/sim/channel/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/log"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire/perunio"
)

// backend implements the utility interface defined in the channel package.
Expand Down
2 changes: 1 addition & 1 deletion backend/sim/wallet/address_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/stretchr/testify/assert"
pkgtest "polycry.pt/poly-go/test"

"perun.network/go-perun/pkg/io/test"
"perun.network/go-perun/wire/perunio/test"
)

func TestGenericMarshaler(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion backend/sim/wallet/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/pkg/errors"

"perun.network/go-perun/log"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire/perunio"
)

var curve = elliptic.P256()
Expand Down
4 changes: 2 additions & 2 deletions backend/sim/wallet/wallet_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

"github.com/stretchr/testify/assert"

"perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet/test"
"perun.network/go-perun/wire/perunio"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down Expand Up @@ -102,7 +102,7 @@ func newWalletSetup(rng *rand.Rand) *test.Setup {

addressNotInWallet := NewRandomAccount(rng).Address()
var buff bytes.Buffer
err = io.Encode(&buff, addressNotInWallet)
err = perunio.Encode(&buff, addressNotInWallet)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion channel/actionmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/pkg/errors"

perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire/perunio"
)

// An ActionMachine is the channel pushdown automaton around an ActionApp.
Expand Down
2 changes: 1 addition & 1 deletion channel/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"log"
"math/big"

perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wire/perunio"
perunbig "polycry.pt/poly-go/math/big"

"github.com/ethereum/go-ethereum/accounts/abi"
Expand Down
4 changes: 2 additions & 2 deletions channel/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
perunio "perun.network/go-perun/pkg/io"
iotest "perun.network/go-perun/pkg/io/test"
"perun.network/go-perun/wire/perunio"
iotest "perun.network/go-perun/wire/perunio/test"
pkgbig "polycry.pt/poly-go/math/big"
pkgtest "polycry.pt/poly-go/test"
)
Expand Down
2 changes: 1 addition & 1 deletion channel/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/pkg/errors"

perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire/perunio"
)

type (
Expand Down
14 changes: 7 additions & 7 deletions channel/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"github.com/pkg/errors"

"perun.network/go-perun/log"
"perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire/perunio"
"polycry.pt/poly-go/math/big"
)

Expand All @@ -31,13 +31,13 @@ type Index uint16

// Encode encodes the object onto an io.Writer.
func (i Index) Encode(w stdio.Writer) error {
return io.Encode(w, uint16(i))
return perunio.Encode(w, uint16(i))
}

// Decode decodes an object from an io.Reader.
func (i *Index) Decode(r stdio.Reader) error {
var _i uint16
err := io.Decode(r, &_i)
err := perunio.Decode(r, &_i)
*i = Index(_i)
return err
}
Expand Down Expand Up @@ -65,8 +65,8 @@ type (
)

var (
_ Source = (*machine)(nil)
_ io.Serializer = (*Phase)(nil)
_ Source = (*machine)(nil)
_ perunio.Serializer = (*Phase)(nil)
)

// Phases known to the channel machine.
Expand Down Expand Up @@ -106,12 +106,12 @@ func (p Phase) String() string {

// Encode serializes a Phase.
func (p Phase) Encode(w stdio.Writer) error {
return io.Encode(w, uint8(p))
return perunio.Encode(w, uint8(p))
}

// Decode deserializes a Phase.
func (p *Phase) Decode(r stdio.Reader) error {
return io.Decode(r, (*uint8)(p))
return perunio.Decode(r, (*uint8)(p))
}

func (t PhaseTransition) String() string {
Expand Down
2 changes: 1 addition & 1 deletion channel/mock_app_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"github.com/stretchr/testify/assert"

iotest "perun.network/go-perun/pkg/io/test"
wallettest "perun.network/go-perun/wallet/test"
iotest "perun.network/go-perun/wire/perunio/test"
pkgtest "polycry.pt/poly-go/test"
)

Expand Down
12 changes: 6 additions & 6 deletions channel/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/pkg/errors"

"perun.network/go-perun/log"
"perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire/perunio"
)

// IDLen the length of a channelID.
Expand Down Expand Up @@ -52,7 +52,7 @@ func NonceFromBytes(b []byte) Nonce {
// Zero is the default channelID.
var Zero = ID{}

var _ io.Serializer = (*Params)(nil)
var _ perunio.Serializer = (*Params)(nil)

// Params are a channel's immutable parameters. A channel's id is the hash of
// (some of) its parameter, as determined by the backend. All fields should be
Expand Down Expand Up @@ -150,12 +150,12 @@ func (p *Params) Clone() *Params {
clonedParts := make([]wallet.Address, len(p.Parts))
for i, v := range p.Parts {
var buff bytes.Buffer
if err := io.Encode(&buff, v); err != nil {
if err := perunio.Encode(&buff, v); err != nil {
log.WithError(err).Panic("Could not encode part")
}

addr := wallet.NewAddress()
if err := io.Decode(&buff, addr); err != nil {
if err := perunio.Decode(&buff, addr); err != nil {
log.WithError(err).Panic("Could not clone params' addresses")
}
clonedParts[i] = addr
Expand All @@ -174,7 +174,7 @@ func (p *Params) Clone() *Params {

// Encode uses the pkg/io module to serialize a params instance.
func (p *Params) Encode(w stdio.Writer) error {
return io.Encode(w,
return perunio.Encode(w,
p.ChallengeDuration,
wallet.AddressesWithLen(p.Parts),
OptAppEnc{p.App},
Expand All @@ -195,7 +195,7 @@ func (p *Params) Decode(r stdio.Reader) error {
virtual bool
)

err := io.Decode(r,
err := perunio.Decode(r,
&challengeDuration,
&parts,
OptAppDec{App: &app},
Expand Down
6 changes: 3 additions & 3 deletions channel/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/channel/test"
"perun.network/go-perun/pkg/io"
iotest "perun.network/go-perun/pkg/io/test"
"perun.network/go-perun/wire/perunio"
iotest "perun.network/go-perun/wire/perunio/test"
pkgtest "polycry.pt/poly-go/test"
)

Expand All @@ -32,7 +32,7 @@ func TestParams_Clone(t *testing.T) {

func TestParams_Serializer(t *testing.T) {
rng := pkgtest.Prng(t)
params := make([]io.Serializer, 10)
params := make([]perunio.Serializer, 10)
for i := range params {
var p *channel.Params
if i&1 == 0 {
Expand Down
2 changes: 1 addition & 1 deletion channel/persistence/keyvalue/persistedstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"io"

"perun.network/go-perun/channel"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wire/perunio"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion channel/persistence/keyvalue/persister.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/pkg/errors"

"perun.network/go-perun/channel"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wire"
"perun.network/go-perun/wire/perunio"
"polycry.pt/poly-go/sortedkv"
)

Expand Down
2 changes: 1 addition & 1 deletion channel/persistence/keyvalue/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

"perun.network/go-perun/channel"
"perun.network/go-perun/channel/persistence"
perunio "perun.network/go-perun/pkg/io"
"perun.network/go-perun/wallet"
"perun.network/go-perun/wire"
"perun.network/go-perun/wire/perunio"
"polycry.pt/poly-go/sortedkv"
)

Expand Down
Loading

0 comments on commit 4392ab6

Please sign in to comment.