network/newstream: merge new stream protocol wire protocol changes, changes to docs, add basic protocol handlers and placeholders
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
// Copyright 2019 The Swarm Authors
|
|
// This file is part of the Swarm library.
|
|
//
|
|
// The Swarm library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The Swarm library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the Swarm library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package newstream
|
|
|
|
import (
|
|
"flag"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/log"
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
"github.com/ethersphere/swarm/network"
|
|
"github.com/ethersphere/swarm/storage/localstore"
|
|
"github.com/ethersphere/swarm/storage/mock"
|
|
)
|
|
|
|
var (
|
|
loglevel = flag.Int("loglevel", 5, "verbosity of logs")
|
|
)
|
|
|
|
func init() {
|
|
flag.Parse()
|
|
|
|
log.PrintOrigins(true)
|
|
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(os.Stderr, log.TerminalFormat(false))))
|
|
}
|
|
|
|
func newTestLocalStore(id enode.ID, addr *network.BzzAddr, globalStore mock.GlobalStorer) (localStore *localstore.DB, cleanup func(), err error) {
|
|
dir, err := ioutil.TempDir("", "swarm-stream-")
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
cleanup = func() {
|
|
os.RemoveAll(dir)
|
|
}
|
|
|
|
var mockStore *mock.NodeStore
|
|
if globalStore != nil {
|
|
mockStore = globalStore.NewNodeStore(common.BytesToAddress(id.Bytes()))
|
|
}
|
|
|
|
localStore, err = localstore.New(dir, addr.Over(), &localstore.Options{
|
|
MockStore: mockStore,
|
|
})
|
|
if err != nil {
|
|
cleanup()
|
|
return nil, nil, err
|
|
}
|
|
return localStore, cleanup, nil
|
|
}
|