audiostrike

package
v0.0.0-...-1973a51 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrArtNotFound      = errors.New("ArtServer has no such art")
	ErrInvalidSignature = errors.New("Signature is not valid for the artist pubkey and message")
	ErrPeerNotFound     = errors.New("AustkServer has no such peer")
)

Functions

func CollectResources

func CollectResources(artServer ArtServer) (*art.ArtResources, error)

func NameToID

func NameToID(name string) string

NameToId converts the name or title of an artist, album, or track into a case-insensitive id usable for urls, filenames, etc.

func TitleToHierarchy

func TitleToHierarchy(title string) string

Types

type ArtServer

type ArtServer interface {
	// Get and store artist info.
	StoreArtist(artist *art.Artist) error
	Artists() (map[string]*art.Artist, error)
	Artist(artistId string) (*art.Artist, error)

	// Album: an artist's optional track container to name and sequence tracks
	StoreAlbum(album *art.Album, publisher Publisher) error
	Albums(artistId string) (map[string]*art.Album, error)

	// Get and store Track info.
	StoreTrack(track *art.Track, publisher Publisher) error
	StoreTrackPayload(track *art.Track, bytes []byte) error
	Tracks(artistID string) (map[string]*art.Track, error)
	Track(artistID string, artistTrackID string) (*art.Track, error)
	TrackFilePath(track *art.Track) string

	// Get and store network info.
	StorePeer(peer *art.Peer, publisher Publisher) error
	Peers() (map[string]*art.Peer, error)
	Peer(pubkey string) (*art.Peer, error)

	StorePublication(*art.ArtistPublication) error
}

ArtServer is a repository to store/serve music and related data for this austk node. Implementations may use a database, file system, test fixture, etc.

type AustkServer

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

AustkServer hosts publishingArtist's art for http/tor clients who might pay the lightning node for it.

func NewAustkServer

func NewAustkServer(cfg *Config, localStorage ArtServer, publisher Publisher) (*AustkServer, error)

NewAustkServer creates a new network Server to serve the configured artist's art.

func (*AustkServer) Artist

func (server *AustkServer) Artist() (*art.Artist, error)

Artist gets the Artist publishing from this server.

func (*AustkServer) Pubkey

func (server *AustkServer) Pubkey() (string, error)

func (*AustkServer) RestHost

func (server *AustkServer) RestHost() string

RestHost returns the tor address or ip address of this austk node.

func (*AustkServer) RestPort

func (server *AustkServer) RestPort() uint32

RestPort returns the tcp/ip port where this austk node listens for requests and serves art.

func (*AustkServer) Sign

func (server *AustkServer) Sign(resources *art.ArtResources) (*art.ArtistPublication, error)

func (*AustkServer) Start

func (s *AustkServer) Start() error

Start the AustkServer listening for REST austk requests for art.

func (*AustkServer) Stop

func (server *AustkServer) Stop() error

Stop the Server

func (*AustkServer) WaitUntilQuitSignal

func (server *AustkServer) WaitUntilQuitSignal()

WaitUntilQuitSignal waits for SIGINT (keyboard interrupt Ctrl-C) or for another reason to quit.

type Client

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

func NewClient

func NewClient(torProxy string, peerAddress string, publisher Publisher) (*Client, error)

NewClient creates a new austk Client to communicate over torProxy with peerAddress.

func (*Client) CloseConnection

func (client *Client) CloseConnection()

CloseConnection closes the onion-routing connection to the peer. This should be called after completing a session with a Client obtained by NewClient.

func (*Client) DownloadTracks

func (client *Client) DownloadTracks(tracks []*art.Track, localStorage ArtServer) (err error)

DownloadTracks downloads tracks over tor from the peer whose pubkey matches the track artist.

The .mp3 file is written as `./tracks/{ArtistId}/{ArtistTrackId}.mp3` That is, tracks download under an artist-specific subdirectory of ./tracks with filenames from the track's ArtistTrackId.

func (*Client) GetAllArtByGrpc

func (client *Client) GetAllArtByGrpc() (*art.ArtistPublication, error)

GetAllArtByGrpc is similar to GetAllArtByTor but uses Grpc rather than raw http over tor. This is dead code for now, as GetAllArtByTor seems to expose the needed functionality. This code may be revived if fields must be specified in the ArtRequest, e.g. for filtering results.

func (*Client) GetAllArtByTor

func (client *Client) GetAllArtByTor() (*art.ArtistPublication, error)

GetAllArtByTor gets the art-directory music metadata over tor from the client's peer.

func (*Client) GetTrack

func (client *Client) GetTrack(artistID string, artistTrackID string) ([]byte, error)

GetTrack gets the mp3 track (the bytes of the mp3 file) artistID/artistTrackID from client's peer by http over tor .

func (*Client) Read

func (client *Client) Read(publication *art.ArtistPublication) (*art.ArtResources, error)

func (*Client) SyncFromPeer

func (client *Client) SyncFromPeer(localStorage ArtServer) (*art.ArtResources, error)

SyncFromPeer gets art resources (music metadata) from client's peer over tor and stores the resources in localStorage. It does not retrieve the mp3 payloads but just the metadata.

type Config

type Config struct {
	ArtistID       string `long:"artist" description:"artist id for publishing tracks"`
	ArtistName     string `long:"name" description:"artist name with proper case, punctuation, spacing, etc."`
	ConfigFilename string `long:"config" description:"config file"`
	AddMp3Filename string `long:"add" description:"mp3 file to add"`
	ArtDir         string `long:"dir" description:"directory storing music art/artist/album/track"`
	TorProxy       string `long:"torproxy" description:"onion-routing proxy"`
	PeerAddress    string `long:"peer" description:"audiostrike server peer to connect"`
	Pubkey         string `long:"pubkey"`
	RestHost       string `long:"host" description:"ip/tor address for this audiostrike service"`
	RestPort       int    `long:"port" description:"port where audiostrike protocol is exposed"`
	ListenOn       string // ip address and port to listen, e.g. 0.0.0.0:53545
	TlsCertPath    string `long:"tlscert" description:"file path for tls cert"`
	MacaroonPath   string `long:"macaroon" description:"file path for macaroon"`
	LndHost        string `long:"lndhost" description:"ip/onion address of lnd"`
	LndGrpcPort    int    `long:"lndport" description:"port where lnd exposes grpc"`

	PlayMp3     bool `long:"play" description:"play imported mp3 file (requires -file)"`
	RunAsDaemon bool `long:"daemon" description:"run as daemon until quit signal (e.g. SIGINT)"`

	Listeners     []net.Addr
	RESTListeners []net.Addr
	RPCListeners  []net.Addr
	ExternalIPs   []net.Addr
}

Config for austk server. These settings are specified in defaults, a config file, or the command line. (Config file not yet implemented)

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig reads each config value from command line or config file or defaults.

type FileServer

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

func NewFileServer

func NewFileServer(artDirPath string) (*FileServer, error)

NewFileServer creates a new FileServer to save and serve art in sudirectories of artDirPath.

func (*FileServer) AlbumTracks

func (fileServer *FileServer) AlbumTracks(artistID string, albumID string) (map[uint32]*art.Track, error)

func (*FileServer) Albums

func (fileServer *FileServer) Albums(artistId string) (map[string]*art.Album, error)

func (*FileServer) Artist

func (fileServer *FileServer) Artist(artistID string) (*art.Artist, error)

func (*FileServer) Artists

func (fileServer *FileServer) Artists() (map[string]*art.Artist, error)

func (*FileServer) Peer

func (fileServer *FileServer) Peer(pubkey string) (*art.Peer, error)

func (*FileServer) Peers

func (fileServer *FileServer) Peers() (map[string]*art.Peer, error)

func (*FileServer) StoreAlbum

func (fileServer *FileServer) StoreAlbum(album *art.Album, publisher Publisher) error

func (*FileServer) StoreArtist

func (fileServer *FileServer) StoreArtist(artist *art.Artist) error

StoreArtist validates the given artist and stores it in memory.

func (*FileServer) StorePeer

func (fileServer *FileServer) StorePeer(peer *art.Peer, publisher Publisher) error

StorePeer stores the peer in the in-memory database.

func (*FileServer) StorePublication

func (fileServer *FileServer) StorePublication(publication *art.ArtistPublication) error

StorePublication saves a file with the published artist details, albums, tracks, and peers.

func (*FileServer) StoreTrack

func (fileServer *FileServer) StoreTrack(track *art.Track, publisher Publisher) error

StoreTrack stores track metadata in the in-memory database.

func (*FileServer) StoreTrackPayload

func (fileServer *FileServer) StoreTrackPayload(track *art.Track, payload []byte) error

StoreTrackPayload stores the mp3 bytes of the given track.

func (*FileServer) Track

func (fileServer *FileServer) Track(artistID string, trackID string) (*art.Track, error)

func (*FileServer) TrackFilePath

func (fileServer *FileServer) TrackFilePath(track *art.Track) string

func (*FileServer) Tracks

func (fileServer *FileServer) Tracks(artistID string) (map[string]*art.Track, error)

type LightningNode

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

func NewLightningNode

func NewLightningNode(cfg *Config, localStorage ArtServer) (*LightningNode, error)

func (*LightningNode) Artist

func (lightningNode *LightningNode) Artist() (*art.Artist, error)

func (*LightningNode) Pubkey

func (lightningNode *LightningNode) Pubkey() (string, error)

Pubkey returns the pubkey for the lnd server, which clients can use to authenticate publications from this node.

func (*LightningNode) Sign

func (lightningNode *LightningNode) Sign(resources *art.ArtResources) (*art.ArtistPublication, error)

getAllArtHandler handles a request to get all the art from the ArtService.

func (*LightningNode) ValidatePublication

func (lightningNode *LightningNode) ValidatePublication(publication *art.ArtistPublication) (*art.ArtResources, error)

type Mp3

type Mp3 struct {
	Tags map[string]string
	// contains filtered or unexported fields
}

Mp3 exposes the Tags (mp3 metadata) and bytes of a given .mp3 file.

func OpenMp3ToRead

func OpenMp3ToRead(path string) (mp3 *Mp3, err error)

OpenMp3ToRead opens an mp3 file to read its data and tags (metadata)

func (*Mp3) AlbumTitle

func (mp3 *Mp3) AlbumTitle() (string, bool)

func (*Mp3) ArtistName

func (mp3 *Mp3) ArtistName() string

func (*Mp3) PlayAndWait

func (mp3 *Mp3) PlayAndWait() error

func (*Mp3) ReadBytes

func (mp3 *Mp3) ReadBytes() ([]byte, error)

ReadBytes returns the raw data from the .mp3 file.

func (*Mp3) Title

func (mp3 *Mp3) Title() string

type Publisher

type Publisher interface {
	Artist() (*art.Artist, error)
	Pubkey() (pubkey string, err error)
	Sign(*art.ArtResources) (publication *art.ArtistPublication, err error)
}

Jump to

Keyboard shortcuts

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