Example #1
0
	errMsgParseError     = "Parse error"
	errMsgInvalidRequest = "Invalid Request"
	errMsgMethodNotFound = "Method not found"
	errMsgInvalidParams  = "Invalid params"
	errMsgInternalError  = "Internal error"

	errMsgNotPost = "only support http POST"

	errMsgInvalidJsonrpc = "invalid jsonrpc"

	// -32000 to -32099	Server error	Reserved for implementation-defined server-errors.

	jsonRPC = "2.0"
)

var logger = util.MustGetLogger("webrpc")

// Request rpc request struct
type Request struct {
	ID      string          `json:"id"`
	Jsonrpc string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

// RPCError response error
type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    string `json:"data,omitempty"`
}
Example #2
0
import (
	"errors"
	"fmt"

	"log"
	"time"

	"github.com/skycoin/skycoin/src/cipher"
	"github.com/skycoin/skycoin/src/coin"
	"github.com/skycoin/skycoin/src/util"
	"github.com/skycoin/skycoin/src/visor/blockdb"
	"github.com/skycoin/skycoin/src/visor/historydb"
)

var (
	logger = util.MustGetLogger("visor")
)

// VisorConfig configuration parameters for the Visor
type VisorConfig struct {
	// Is this the master blockchain
	IsMaster bool

	//WalletDirectory string //move out

	//Public key of blockchain authority
	BlockchainPubkey cipher.PubKey

	//Secret key of blockchain authority (if master)
	BlockchainSeckey cipher.SecKey
Example #3
0
var (
	// Filename for disk-cached peers
	PeerDatabaseFilename = "peers.txt"
	// Filename for disk-cached blacklisted peers
	BlacklistedDatabaseFilename = "blacklisted_peers.txt"
	// Returned when the Pex is at a maximum
	PeerlistFullError = errors.New("Peer list full")
	// Returned when an address appears malformed
	InvalidAddressError = errors.New("Invalid address")
	// Returned when attempting to add a blacklisted peer
	BlacklistedAddressError = errors.New("Blacklisted address")
	// How often to updated expired entries in the blacklist
	RefreshBlacklistRate = time.Second * 30
	// Logging. See http://godoc.org/github.com/op/go-logging for
	// instructions on how to include this log's output
	logger = util.MustGetLogger("pex")
	// Default rng
	rnum = rand.New(rand.NewSource(time.Now().Unix()))
	// For removing inadvertent whitespace from addresses
	whitespaceFilter = regexp.MustCompile("\\s")
)

// Returns true if ipPort is a valid ip:host string
func ValidateAddress(ipPort string, allowLocalhost bool) bool {
	ipPort = whitespaceFilter.ReplaceAllString(ipPort, "")
	pts := strings.Split(ipPort, ":")
	if len(pts) != 2 {
		return false
	}
	ip := net.ParseIP(pts[0])
	if ip == nil {
Example #4
0
package coin

import (
	"fmt"
	"log"

	"github.com/skycoin/skycoin/src/aether/encoder"
	"github.com/skycoin/skycoin/src/cipher"
	"github.com/skycoin/skycoin/src/util"
)

var logger = util.MustGetLogger("coin")

type Block struct {
	Head BlockHeader
	Body BlockBody
}

// HashPair including current block hash and previous block hash.
type HashPair struct {
	Hash    cipher.SHA256
	PreHash cipher.SHA256
}

type BlockHeader struct {
	Version uint32

	Time  uint64
	BkSeq uint64 //increment every block
	Fee   uint64 //fee in block, used for Proof of Stake
Example #5
0
	"time"

	"github.com/skycoin/skycoin/src/mesh/gui"
	"github.com/skycoin/skycoin/src/mesh/nodemanager"
	"github.com/skycoin/skycoin/src/util"
)

const (
	logModuleName = "skywire.main"

	// logFormat is same as src/util/logging.go#defaultLogFormat
	// logFormat     = "[%{module}:%{level}] %{message}"
)

var (
	logger     = util.MustGetLogger(logModuleName)
	logModules = []string{logModuleName}
)

// default configurations
const (
	webInterfaceEnable = true
	webInterfacePort   = 6480
	webInterfaceAddr   = "127.0.0.1"
	webInterfaceHttps  = false
	launchBrowser      = true
	guiDirectory       = "./src/mesh/gui/static/"
	dataDirectory      = ".skywire"
)

// TODO:
Example #6
0
	logging "github.com/op/go-logging"
	"github.com/skycoin/skycoin/src/api/webrpc"
	"github.com/skycoin/skycoin/src/cipher"
	"github.com/skycoin/skycoin/src/coin"
	"github.com/skycoin/skycoin/src/daemon"
	"github.com/skycoin/skycoin/src/gui"
	"github.com/skycoin/skycoin/src/util"
	"github.com/skycoin/skycoin/src/visor/blockdb"
)

//"github.com/skycoin/skycoin/src/cli"

//"github.com/skycoin/skycoin/src/wallet"

var (
	logger     = util.MustGetLogger("main")
	logFormat  = "[skycoin.%{module}:%{level}] %{message}"
	logModules = []string{
		"main",
		"daemon",
		"coin",
		"gui",
		"util",
		"visor",
		"wallet",
		"gnet",
		"pex",
		"webrpc",
	}

	//TODO: Move time and other genesis block settigns from visor, to here
Example #7
0
	"crypto/tls"
	"fmt"
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"path/filepath"

	"github.com/skycoin/skycoin/src/daemon"
	"github.com/skycoin/skycoin/src/util"

	wh "github.com/skycoin/skycoin/src/util/http" //http,json helpers
)

var (
	logger = util.MustGetLogger("gui")
)

const (
	resourceDir = "dist/"
	devDir      = "dev/"
	indexPage   = "index.html"
)

// Begins listening on http://$host, for enabling remote web access
// Does NOT use HTTPS
func LaunchWebInterface(host, staticDir string, daemon *daemon.Daemon) error {
	logger.Info("Starting web interface on http://%s", host)
	logger.Warning("HTTPS not in use!")
	appLoc, err := util.DetermineResourcePath(staticDir, resourceDir, devDir)
	if err != nil {
Example #8
0
	"bytes"
	"crypto/sha256"
	"encoding/hex"
	"errors"
	"hash"
	"log"
	"time"

	"github.com/skycoin/skycoin/src/cipher/ripemd160"
	"github.com/skycoin/skycoin/src/util"

	"github.com/skycoin/skycoin/src/cipher/secp256k1-go"
)

var (
	logger      = util.MustGetLogger("crypto")
	DebugLevel1 = true //checks for extremely unlikely conditions (10e-40)
	DebugLevel2 = true //enable checks for impossible conditions
)

type PubKey [33]byte
type PubKeySlice []PubKey

func (slice PubKeySlice) Len() int {
	return len(slice)
}

func (slice PubKeySlice) Less(i, j int) bool {
	return bytes.Compare(slice[i][:], slice[j][:]) < 0
}
Example #9
0
package wallet

import (
	"fmt"
	"time"

	"encoding/hex"

	"github.com/skycoin/skycoin/src/cipher"
	"github.com/skycoin/skycoin/src/util"
	//"math/rand"
)

var (
	logger = util.MustGetLogger("wallet")
)

const WalletExt = "wlt"
const WalletTimestampFormat = "2006_01_02"

//check for collisions and retry if failure
func NewWalletFilename() string {
	timestamp := time.Now().Format(WalletTimestampFormat)
	//should read in wallet files and make sure does not exist
	padding := hex.EncodeToString((cipher.RandByte(2)))
	return fmt.Sprintf("%s_%s.%s", timestamp, padding, WalletExt)
}
Example #10
0
	//	"Could Not Connect Error")

	// Blacklist a peer when they get disconnected for these
	// DisconnectReasons

	BlacklistOffenses = map[gnet.DisconnectReason]time.Duration{
		//DisconnectSelf:                      time.Second * 1,
		//DisconnectIntroductionTimeout:       time.Second * 1,
		DisconnectNoIntroduction:            time.Minute * 20,
		gnet.DisconnectInvalidMessageLength: time.Minute * 20,
		gnet.DisconnectMalformedMessage:     time.Minute * 20,
		gnet.DisconnectUnknownMessage:       time.Minute * 20,
		//ConnectFailed:                       time.Minute * 60,
	}

	logger = util.MustGetLogger("daemon")
)

// Subsystem configurations
type Config struct {
	Daemon   DaemonConfig
	Messages MessagesConfig
	Pool     PoolConfig
	Peers    PeersConfig
	Gateway  GatewayConfig
	Visor    VisorConfig
}

// Returns a Config with defaults set
func NewConfig() Config {
	return Config{
Example #11
0
	"io/ioutil"
	"log"
	"net"
	"net/http"
	//"os"
	"path/filepath"
	//"strings"

	"github.com/skycoin/skycoin/src/mesh/nodemanager"
	"github.com/skycoin/skycoin/src/util"

	wh "github.com/skycoin/skycoin/src/util/http" //http,json helpers
)

var (
	logger = util.MustGetLogger("skywire.gui")
)

const (
	resourceDir = "dist/"
	devDir      = "dev/"
	indexPage   = "index.html"
)

// Begins listening on http://$host, for enabling remote web access
// Does NOT use HTTPS
func LaunchWebInterface(host, staticDir string, nm *nodemanager.NodeManager) error {
	logger.Info("Starting web interface on http://%s", host)
	logger.Warning("HTTPS not in use!")
	logger.Info("Web resources directory: %s", staticDir)
Example #12
0
		"Write failed")
	DisconnectSetReadDeadlineFailed = errors.New(
		"SetReadDeadline failed")
	DisconnectInvalidMessageLength DisconnectReason = errors.New(
		"Invalid message length")
	DisconnectMalformedMessage DisconnectReason = errors.New(
		"Malformed message body")
	DisconnectUnknownMessage DisconnectReason = errors.New(
		"Unknown message ID")
	DisconnectWriteQueueFull DisconnectReason = errors.New(
		"Write queue full")
	DisconnectUnexpectedError DisconnectReason = errors.New(
		"Unexpected error encountered")

	// Logger
	logger = util.MustGetLogger("gnet")
)

type Config struct {
	// Address to listen on. Leave empty for arbitrary assignment
	Address string
	// Port to listen on. Set to 0 for arbitrary assignment
	Port uint16
	// Connection limits
	MaxConnections int
	// Messages greater than length are rejected and the sender disconnected
	MaxMessageLength int
	// Timeout is the timeout for dialing new connections.  Use a
	// timeout of 0 to ignore timeout.
	DialTimeout time.Duration
	// Timeout for reading from a connection. Set to 0 to default to the