logbuddy

package module
v0.0.0-...-15acfb0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2015 License: Apache-2.0 Imports: 26 Imported by: 0

README

Build Status

App Usage

Pending initial release.

WebSocket API

Still WIP

Documentation

Index

Constants

View Source
const (

	//BadMsg represents bad messages
	BadMsg = -1
	//InitMsg Initialization Message
	InitMsg = 0
	//DataMsg Data Message
	DataMsg = 1
	//ReqMsg New request Message
	ReqMsg = 2
	//ErrMsg Error Message
	ErrMsg = 3
	//CtrlMsg Control Message
	CtrlMsg = 4
	//RestartMsg Restart Message
	RestartMsg = 5
	//StartMsg Start Message
	StartMsg = 100
	//AckStartMsg acknowledge start Message
	AckStartMsg = 101
	//StopMsg Stop Message
	StopMsg = 255
)
View Source
const (
	//CookieName the cookie key that represents the session
	CookieName = "lbid"
)
View Source
const (
	//MaxReadBuffer Max mempory allocated to a server socket for listening
	MaxReadBuffer = 1048576
)

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func RestoreAsset

func RestoreAsset(dir, name string) error

Restore an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

Restore assets under the given directory recursively

Types

type BinFileStorage

type BinFileStorage struct {
	Location *url.URL        //location of the storage file
	MsgChan  chan LogMessage //Channel to recieve messages from
	LogFile  *os.File        //File the file being used
}

BinFileStorage Store logs in a binary format

func NewBinFileStorage

func NewBinFileStorage(loc *url.URL) *BinFileStorage

NewBinFileStorage Create an initialized NewBinFileStorage

func (*BinFileStorage) Close

func (s *BinFileStorage) Close() error

Close Close the file for writing

func (*BinFileStorage) Open

func (s *BinFileStorage) Open() error

Open Open the file for writing

func (*BinFileStorage) Read

func (s *BinFileStorage) Read(data ...[]byte) error

Read Reads data from the

func (*BinFileStorage) SetDest

func (s *BinFileStorage) SetDest(dest string) error

SetDest Set the destination URL for writing

func (*BinFileStorage) Write

func (s *BinFileStorage) Write(data ...LogMessage) error

Write Write data to the destination file

type ClientMessage

type ClientMessage struct {
	Type         int          `json:"type"`         //Type Message type
	Channel      int          `json:"channel"`      // channel to listen on
	ServerConfig ServerConfig `json:"serverconfig"` //ServerConfig configuration of requested server
}

ClientMessage Messages sent from the websocket client

type ConfigManager

type ConfigManager struct {
}

ConfigManager manages loading a configuration file for logbuddy

type CtrlChanMsg

type CtrlChanMsg struct {
	Type    int    //Type message type
	Message []byte //Message string message to include with msg
}

CtrlChanMsg control channel message format

func (*CtrlChanMsg) MarshalJSON

func (c *CtrlChanMsg) MarshalJSON() ([]byte, error)

MarshalJSON returns json []byte of CtrlChanMsg

func (*CtrlChanMsg) String

func (c *CtrlChanMsg) String() string

String return string format of message

type FileStorage

type FileStorage struct {
	Location *url.URL        //location of the storage file
	MsgChan  chan LogMessage //Channel to recieve messages from
	LogFile  *os.File        //File the file being used
}

FileStorage Allows data to be written to a file

func NewFileStorage

func NewFileStorage(loc *url.URL) *FileStorage

NewFileStorage Create an initialized NewFileStorage

func (*FileStorage) Close

func (s *FileStorage) Close() error

Close Close the file for writing

func (*FileStorage) Open

func (s *FileStorage) Open() error

Open Open the file for writing

func (*FileStorage) Read

func (s *FileStorage) Read(data ...[]byte) error

Read Reads data from the

func (*FileStorage) SetDest

func (s *FileStorage) SetDest(dest string) error

SetDest Set the destination URL for writing

func (*FileStorage) Write

func (s *FileStorage) Write(data ...LogMessage) error

Write Write data to the destination file

type LogMessage

type LogMessage struct {
	Message []byte `json:"Message"`  //Message
	SrcIP   net.IP `json:"srcip"`    //Src IP of Message
	SrcPort int    `json:"srcport"`  //Src Port of Message
	DstIP   net.IP `json:"destip"`   //Dst IP of Message
	DstPort int    `json:"destport"` //Dest Port of Message
	Network string `json:"network"`  //Network type of Message tcp,tcp4,tcp6,udp,udp4,udp6
}

LogMessage A message containing a log

func (*LogMessage) MarshalJSON

func (m *LogMessage) MarshalJSON() ([]byte, error)

MarshalJSON returns json []byte of LogMessage

func (*LogMessage) String

func (m *LogMessage) String() string

String returns string value of LogMessage

type MsgHandler

type MsgHandler struct {
	Sender    chan interface{}
	Receivers []chan interface{}
}

type MsgRouter

type MsgRouter struct {
	Handlers map[int]*MsgHandler
}

func (*MsgRouter) RegisterReceivers

func (mr *MsgRouter) RegisterReceivers(r chan interface{}, id int) int

func (*MsgRouter) RegisterSender

func (mr *MsgRouter) RegisterSender(s chan interface{}, id int)

Register

func (*MsgRouter) UnregisterSender

func (mr *MsgRouter) UnregisterSender(id int)

Unregister

type Server

type Server interface {
	Listen()
	// contains filtered or unexported methods
}

Server interface defining the behaviors of a server

type ServerConfig

type ServerConfig struct {
	ID   int    `json:"id"`   //ID ID of running server, assigned by the server manager
	Type string `json:"type"` // udp,udp4,udp6,tcp,tcp4,tcp6
	IP   string `json:"ip"`   // IP Address in string format
	Port int    `json:"port"` // Port to listen in, < 1024 requires root permission
}

ServerConfig Specifies the network configuration of the server

func (*ServerConfig) MarshalJSON

func (sc *ServerConfig) MarshalJSON() ([]byte, error)

MarshalJSON Returns json marshalled LogMessage

type ServerManager

type ServerManager struct {
	ServerConfigs map[int]*ServerConfig
	CtrlChans     map[int]chan CtrlChanMsg

	MsgChans map[int]chan LogMessage
	ErrChans map[int]chan error
	// contains filtered or unexported fields
}

ServerManager Manages listening servers

func NewServerManager

func NewServerManager() *ServerManager

NewServerManager Creates a new server manager with an initalized CtrlChans map

func (*ServerManager) Register

func (s *ServerManager) Register(id int) (chan LogMessage, chan CtrlChanMsg)

Register Returns the LogMessage channel of an associated server

func (*ServerManager) StartServer

func (s *ServerManager) StartServer(config *ServerConfig) (id int, err error)

StartServer Start a new server with a server config

func (*ServerManager) StopServer

func (s *ServerManager) StopServer(id int) error

StopServer Stop a server specified by IP

type Storage

type Storage interface {
	Write(...LogMessage) error
	Read() error //Read data from the
	SetDest(string) error
	Open() error  //Opens the storage location for writing
	Close() error //Closes the storage location
}

Storage an interface for all storage types

type TCPServer

type TCPServer struct {
	Config *ServerConfig
	// contains filtered or unexported fields
}

TCPServer A server to listen for TCP messages

func NewTCPServer

func NewTCPServer(errChan chan error, ctrlChan chan CtrlChanMsg, msgChan chan LogMessage, config *ServerConfig) *TCPServer

NewTCPServer Creates a new initialized TCPServer

func (*TCPServer) Listen

func (s *TCPServer) Listen()

Listen Starts TCPServer ready to receive messages Typically run as a go routine

type UDPServer

type UDPServer struct {
	Config *ServerConfig
	// contains filtered or unexported fields
}

UDPServer A server to listen for UDP messages

func NewUDPServer

func NewUDPServer(errChan chan error, ctrlChan chan CtrlChanMsg, msgChan chan LogMessage, config *ServerConfig) *UDPServer

NewUDPServer creates a new initialized UDP server

func (*UDPServer) Listen

func (s *UDPServer) Listen()

Listen Listen to

type WSClientMessage

type WSClientMessage struct {
	Type int    `json:"type"` //Type of Message
	ID   int    `json:"id"`   //ID associated with message
	Data []byte `json:"data"` //Payload of Message
}

WSClientMessage A universal message to send to web socket clients

func (*WSClientMessage) AddDataPayload

func (wscm *WSClientMessage) AddDataPayload(data []byte) error

AddDataPayload adds a []byte payload to Data

func (*WSClientMessage) MarshalJSON

func (wscm *WSClientMessage) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON version of WSClientMessage

type WebChanMsg

type WebChanMsg struct {
	Type       int    //Msg type
	LogMessage []byte //LogMessage
	SrcIP      net.IP //Src IP of LogMessage
	SrcPort    int    //Src Port of LogMessage
	DestIP     net.IP //Dst IP of LogMessage
	DestPort   int    //Dest Port of LogMessage
	Network    string //Network type of LogMessage
}

type WebClientMgr

type WebClientMgr struct {
	Clients       map[string]*http.Cookie //maps clients based upon cookies
	ClientServers map[string][]int
	// contains filtered or unexported fields
}

WebClientMgr manages web clients to ensure persistance across sessions

func NewWebClientMgr

func NewWebClientMgr() *WebClientMgr

NewWebClientMgr Returns an initalized web client manager

func (*WebClientMgr) ReconnectSession

func (wcm *WebClientMgr) ReconnectSession(chanID int) (chan LogMessage, chan CtrlChanMsg)

ReconnectSession Returns an existing Message channel based on chanID

func (*WebClientMgr) StartServer

func (wcm *WebClientMgr) StartServer(client string, config *ServerConfig) (chan LogMessage, chan CtrlChanMsg)

StartServer starts a new server for a web client

func (*WebClientMgr) StartSession

func (wcm *WebClientMgr) StartSession(w http.ResponseWriter, r *http.Request)

StartSession generates a new cookie for clients and adds the session to the WebClientMgr

func (*WebClientMgr) StartWSSession

func (wcm *WebClientMgr) StartWSSession(w http.ResponseWriter, r *http.Request, conn *websocket.Conn) (string, []chan LogMessage, []chan CtrlChanMsg)

StartWSSession Starts a websocket session with the WebClientMgr allows it to setup existing session information

func (*WebClientMgr) StopSession

func (wcm *WebClientMgr) StopSession(id string)

StopSession stops an existing session for a client. Also stops all existing servers.

type WebServer

type WebServer struct {
	Address string //Address the address to listen on

	ClientMgr *WebClientMgr //Client manager manages the state of clients
	// contains filtered or unexported fields
}

WebServer Serves the user front end and APIs

func (*WebServer) Close

func (ws *WebServer) Close() error

Close Stop the web server and close existing clients

func (*WebServer) HomeHandler

func (ws *WebServer) HomeHandler(w http.ResponseWriter, r *http.Request)

func (*WebServer) Listen

func (ws *WebServer) Listen() error

Listen set webserver to listen

func (*WebServer) RegisterLogger

func (ws *WebServer) RegisterLogger(id int) (msgChan chan LogMessage, err error)

RegisterLogger Registers a logger to be sent to the connection

func (*WebServer) ServeStatic

func (ws *WebServer) ServeStatic(w http.ResponseWriter, r *http.Request)

ServeStatic Serves static content

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL