Documentation ¶
Overview ¶
Package network takes care of networking for degdb.
Index ¶
- Variables
- type Closable
- type Conn
- type Server
- func (s *Server) Broadcast(hash *uint64, msg *protocol.Message) error
- func (s *Server) Connect(addr string) error
- func (s *Server) HTTPHandle(route string, handler http.Handler)
- func (s *Server) HTTPHandleFunc(route string, handler func(w http.ResponseWriter, r *http.Request))
- func (s *Server) Handle(typ string, f protocolHandler)
- func (s *Server) Listen() error
- func (s *Server) ListenWait()
- func (s *Server) LocalID() string
- func (s *Server) LocalKeyspace() *protocol.Keyspace
- func (s *Server) LocalPeer() *protocol.Peer
- func (s *Server) MinimumCoveringPeers() []*Conn
- func (s *Server) NewConn(c net.Conn) *Conn
- func (s *Server) Stop()
Constants ¶
This section is empty.
Variables ¶
var ( IndexTemplate = template.Must(template.New("").Parse(staticBox.MustString("common/index.html"))) ErrorTemplate = template.Must(template.New("").Parse(staticBox.MustString("common/error.html"))) )
var (
ErrNoRecipients = errors.New("no recipients for the message were found")
)
var Timeout = errors.New("request timed-out")
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct { Peer *protocol.Peer Closed bool net.Conn // contains filtered or unexported fields }
Conn is a net.Conn with extensions.
func (*Conn) Request ¶
Request sends a message on a connection and waits for a response. Returns error network.Timeout if no response in 10 seconds.
type Server ¶
type Server struct { IP string Port int Serving bool HTTP *http.Server Peers map[string]*Conn *log.Logger // contains filtered or unexported fields }
Server handles all network traffic.
func NewServer ¶
NewServer creates a new server with routing information. If log is nil, stdout is used.
func (*Server) Broadcast ¶
Broadcast sends a message to all peers with that have the hash in their keyspace. If there is no peer that can receive the message, ErrNoRecipients is returned.
func (*Server) HTTPHandleFunc ¶
func (*Server) ListenWait ¶
func (s *Server) ListenWait()
ListenWait waits for the server to start accepting connections before returning.
func (*Server) LocalKeyspace ¶
LocalKeyspace returns the keyspace that the local node represents.
func (*Server) MinimumCoveringPeers ¶
MinimumCoveringPeers returns a set of peers that minimizes overlap. This is similar to the Set Covering Problem and is NP-hard. This is a greedy algorithm. While the keyspace is not entirely covered, scan through all peers and pick the peer that will add the most to the set while still having the start in the selected set. TODO(wiz): Make this more optimal. TODO(wiz): achieve n-redundancy
Directories ¶
Path | Synopsis |
---|---|
Package customhttp is a reimplementation of http.FileServer that supports custom HTML templates for errors and directory listings.
|
Package customhttp is a reimplementation of http.FileServer that supports custom HTML templates for errors and directory listings. |
Package ip returns the current IP address by contacting a number of public servers.
|
Package ip returns the current IP address by contacting a number of public servers. |