Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Latest commit

 

History

History
283 lines (176 loc) · 7.56 KB

server.md

File metadata and controls

283 lines (176 loc) · 7.56 KB

server

import "Smilo-blackbox/src/server"

p2p.go p2p_func.go server.go server_utils.go

var (

    //StormDBPeers is the main object for peers db
    StormDBPeers *storm.DB

    //DefaultExpirationTime is the default expiration time used on the database
    DefaultExpirationTime = &buntdb.SetOptions{Expires: false} // never expire

    //PUBLIC_SERVER_READ_TIMEOUT_STR will be used to hold env var
    PUBLIC_SERVER_READ_TIMEOUT_STR = os.Getenv("PUBLIC_SERVER_READ_TIMEOUT")

    //PUBLIC_SERVER_WRITE_TIMEOUT_STR will be used to hold env var
    PUBLIC_SERVER_WRITE_TIMEOUT_STR = os.Getenv("PUBLIC_SERVER_WRITE_TIMEOUT")

    //PRIVATE_SERVER_READ_TIMEOUT_STR will be used to hold env var
    PRIVATE_SERVER_READ_TIMEOUT_STR = os.Getenv("PRIVATE_SERVER_READ_TIMEOUT")

    //PRIVATE_SERVER_WRITE_TIMEOUT_STR will be used to hold env var
    PRIVATE_SERVER_WRITE_TIMEOUT_STR = os.Getenv("PRIVATE_SERVER_WRITE_TIMEOUT")
    //PUBLIC_SERVER_READ_TIMEOUT will be used to hold env var
    PUBLIC_SERVER_READ_TIMEOUT = 120
    //PUBLIC_SERVER_WRITE_TIMEOUT will be used to hold env var
    PUBLIC_SERVER_WRITE_TIMEOUT = 120
    //PRIVATE_SERVER_READ_TIMEOUT   will be used to hold env var
    PRIVATE_SERVER_READ_TIMEOUT = 60
    //PRIVATE_SERVER_WRITE_TIMEOUT  will be used to hold env var
    PRIVATE_SERVER_WRITE_TIMEOUT = 60
)
func AddPeer(node *discover.Node) error

AddPeer will add a peer

func DoUnixGetJSONRequest(t *testing.T, endpoint string, json string) string

DoUnixGetJSONRequest is used for test real request calls.

func DoUnixPostJSONRequest(t *testing.T, endpoint string, json string) string

DoUnixPostJSONRequest is used for test real request calls.

func DoUnixPostRequest(t *testing.T, endpoint string, payload []byte, headers http.Header) string

DoUnixPostRequest is used for test real request calls.

func DoUnixRequest(t *testing.T, endpoint string) string

DoUnixRequest is used for test real request calls.

func GetExternalIP() (string, error)

GetExternalIP Get the external IP

func GetPeerListSend(peer *p2p.Peer, rw p2p.MsgWriter)

GetPeerListSend will get peers

func GetPeerNodeID(id string) string

GetPeerNodeID will get peer node

func GetSocketClient(socketFile string) http.Client

GetSocketClient is used for test real request calls.

func InitP2PPeers(peers []model.PeerNode)

InitP2PPeers will init peers

func InitP2PServer(bootstrapNodes []*discover.Node) (*p2p.Server, error)

InitP2PServer will init p2p peers

func InitP2p()

InitP2p will init p2p

func InitRouting() (*mux.Router, *mux.Router)

InitRouting will init routing

func IsPeerAlreadyAdded(parsedPeer *discover.Node) bool

IsPeerAlreadyAdded check if peer already connected

func NewServer(Hostaddr, Port string) (*http.Server, *http.Server)

NewServer will create a new http server instance -- pub and private

func PeerList(p2pMessage Message)

PeerList will init all peers provided on the p2p message

func SendMsg(peer *p2p.Peer, rw p2p.MsgWriter, err error, outmsg Message)

SendMsg will send a message

func SetLogger(loggers *logrus.Entry)

SetLogger set the logger

func StartServer()

StartServer will start the server

func SubscribeP2P()

SubscribeP2P will subscribe p2p

type Message struct {
    Header string `json:"content"`
    Body   string `json:"body"`
}

Message holds header and body

type Peer struct {
    ID         string
    Dest       string
    SourcePort int
}

Peer is the main peer struct


Generated by godoc2md