gomahawk

package module
v0.0.0-...-a564318 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2014 License: MIT Imports: 12 Imported by: 1

README

gomahawk

WIP implementation of the Network Protocol of tomahawk in golang

Install

go get github.com/MStoykov/gomahawk

Features

Done

  • Advertising the instance
  • Incoming connections
  • Request for DBConnection
  • Request for StreamConnection
  • All the Documented dbsync commands
  • DBsync from us to the opposite side

Planned

  • Listen for advertising
  • Making ControlConnections
  • Reverse Connections (Requests for connections and Answering Requests)
  • Answering DBConnection requests
  • Answering StreamConnections
  • Basic implementations for some parts needed for the client of gomahawk
    • InMemory searchable database for remote instances
    • etc.
  • Implementing the nondocumented dbsync commands

Usage

Import

import (
	"github.com/MStoykov/gomahawk"
)

Implement Tomahawk Interface

look at examples for more examples of how to use the api

Make new Gomahawk instance

g := NewGomahawkImpl()
gs := gomahawk.NewGomahawkServer(g)
err := gs.ListenTo(net.ParseIP("192.168.1.13"), "50210") // Listen on 192.168.1.13 and the default tomahawk port
// error checking
gs.Start()

Requesting DBConnection

This is used to get the changes from the remote

var gs GomahawkServer
t := gs.Tomahawks()[0] // get the first of the connected Tomahawks
err := t.RequestDBConnection(dbConnectionImpl)  // the dbConnectionImpl is the implemenation of the DBConnection
// error handleing
// the Gomahawk registered with the GomahawkServer gs will get call to 
// NewDBConnection with the Tomahawk instance and the given DBConnection can be used to initializa fetching
dbConnection.FetchOps(fetchOps, "") // get all changes 
// the methods on fetchOps will be called in order and at the end the Close() method will be called
// that signals that all current changes have been transmitted

LICENSE

The MIT License (MIT)

Copyright (c) 2013 Mihail Stoykov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotSupportedConnection = errors.New("Not Supported Connection")
)

Functions

This section is empty.

Types

type DBConnection

type DBConnection interface {
	// Signals that there are changes to the Database since the last FetchOps
	// Should not be called while on the
	Trigger() error
	// request that all changes since the given UUID of a command are send using the given FetchOpsMethod.
	//
	// You can not get or make more then one simultanious FetchOps.
	//
	// "" means all changes otherwise it is a uuid of previously transfered command. Look at the protocol specification for which command's uuids can be used.
	FetchOps(FetchOpsMethod, string) error

	// Close the underlying connection.
	Close() error
}

type DummyFetchOps

type DummyFetchOps struct {
	// contains filtered or unexported fields
}

func (*DummyFetchOps) Close

func (d *DummyFetchOps) Close() (err error)

func (*DummyFetchOps) SendCommand

func (d *DummyFetchOps) SendCommand(command msg.Command) (err error)

type Gomahawk

type Gomahawk interface {
	// Human readable Name
	Name() string

	// A new connection from the given address is requested.
	// If the returned value is true GomahawkServer will continue
	// with the connection otherwise the connection will be closed.
	ConnectionIsRequested(net.Addr) bool

	// Found peer at the given address.
	// Name could be empty.
	// If the returned value is true GomahawkServer will try to connect to it.
	NewTomahawkFound(addr net.Addr, name string) bool

	// The given Tomahawk made DBConnection (by our request).
	//
	NewDBConnection(Tomahawk, DBConnection) (DBConnection, error)

	// The given Tomahawk has requested a DBConnection.
	// If the returned DBConneciton is nil the request will be denied.
	NewDBConnectionRequested(Tomahawk, DBConnection) (DBConnection, error)

	// The given Tomahawk has requested a StreamConnection for file with the given id
	// if the returned connection isn't nil it will be used to stream the file
	NewStreamConnectionRequested(t Tomahawk, uuid string) (StreamConnection, error)
}

type GomahawkServer

type GomahawkServer interface {
	// Listen to the given port and ip. The default port is 50210
	// error is being returned if that is not possible
	ListenTo(ip net.IP, port int) error
	// start the listening and advertising
	Start() error
	// says to advertise this instance
	// (this is regardless of advertisement period set by AdvertEvery)
	Advertise() error
	// Sets a period of time that the advert will be sent.
	//
	// By default 0 which means never
	AdvertiseEvery(seconds int)
	// retuns the name. This is the same as the Gomahawk.Name() for the Gomahawk instance
	// given to GomahawkServer
	Name() string
	// returns the currently connected tomahawks
	GetTomahawks() []Tomahawk
}

GomahawkServer

func NewGomahawkServer

func NewGomahawkServer(gomahawk Gomahawk) (result GomahawkServer, err error)

returns new instance of Gomahawk

type StreamConnection

type StreamConnection interface {
	// returns the ID of the file associated with this connection
	FileID() int64
	// return the current stream. Multiple calls to this function without SeekToBlock
	// return the same channel
	GetStream() (<-chan []byte, error)
	// this will close the previos stream and make a new one that will start giving blocks from the given index forward
	// the size of block is not set but it should be considered constant for each StreamConnection
	//
	// The original Tomahawk has it hardcoded to 4096 bytes at the time of writing
	SeekToBlock(blockIndex int) error
}

The StreamConnection is used to transfer files over the network

type Tomahawk

type Tomahawk interface {
	// Returns a human readable name of the instance. Can be empty string
	Name() string
	// Returns the uuid of the tomahawk instance as a string.
	//
	// While implementing this interface you can use "" and a uuid based on the name
	UUID() string
	// Get a streamConnection for the file with the given id previously received from AddFiles command from this tomahawk.
	//
	// NotSupportedConnection is returned when this type of connection is not supported
	// Others error mean that the connection was not successfully created
	RequestStreamConnection(uuid int64) (StreamConnection, error)
	// A non blocking request for a DBConnection
	// a call to NewDBConnection with the associated Tomahawk and the DBConnection will be made
	// when and if the remote tomahawks agrees to it.
	// Multiple calls to this
	//
	// NotSupportedConnection is returned when this type of connection is not supported
	// Others error mean that the connection was not successfully created
	RequestDBConnection(DBConnection) error

	// The last time a ping message was received from this particular Tomahawk
	LastPing() time.Time
}

This is the Interface that represents a remote Tomahawk.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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