murcott

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

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

Go to latest
Published: Dec 25, 2014 License: MIT Imports: 6 Imported by: 0

README

murcott

Decentralized instant messaging framework

Build Status GoDoc

Installation

go get github.com/h2so5/murcott

Example

package main

import (
	"fmt"
	"github.com/h2so5/murcott"
	"os"
	"strings"
)

func main() {
	// Private key identifies the ownership of your node.
	key := utils.GeneratePrivateKey()
	fmt.Println("Your node id: " + key.PublicKeyHash().String())

	// Storage keeps client's persistent data.
	storage := utils.NewStorage("storage.sqlite3")

	// Create a client with the private key and the storage.
	client, _ := utils.NewClient(key, storage, utils.DefaultConfig)

	// Handle incoming messages.
	client.HandleMessages(func(src utils.NodeID, msg utils.ChatMessage) {
		fmt.Println(msg.Text() + " from " + src.String())
	})

	// Start client's mainloop.
	go client.Run()

	// Parse a base58-encoded node identifier of your friend.
	dst, _ := utils.NewNodeIDFromString("3CjjdZLV4DqXkc3KtPZPTfBU1AAY")

	for {
		b := make([]byte, 1024)
		len, err := os.Stdin.Read(b)
		if err != nil {
			break
		}
		str := strings.TrimSpace(string(b[:len]))
		if str == "quit" {
			break
		}

		// Send message to the destination node.
		client.SendMessage(dst, utils.NewPlainChatMessage(str), func(ok bool) {
			if !ok {
				fmt.Println("Failed to deliver the message to the node...")
			}
		})
	}

	// Stop client's mainloop.
	client.Close()
}

License

MIT License

Documentation

Overview

Package murcott is a decentralized instant messaging framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Roster *client.Roster
	Logger *log.Logger
	// contains filtered or unexported fields
}

func NewClient

func NewClient(key *utils.PrivateKey, config utils.Config) (*Client, error)

NewClient generates a Client with the given PrivateKey.

func (*Client) Close

func (c *Client) Close()

Stops the current mainloop.

func (*Client) HandleMessages

func (c *Client) HandleMessages(handler func(src utils.NodeID, msg client.ChatMessage))

HandleMessages registers the given function as a massage handler.

func (*Client) HandleStatuses

func (c *Client) HandleStatuses(handler func(src utils.NodeID, status client.UserStatus))

HandleStatuses registers the given function as a status handler.

func (*Client) ID

func (c *Client) ID() utils.NodeID

func (*Client) MarshalCache

func (c *Client) MarshalCache() (data []byte, err error)

func (*Client) Nodes

func (c *Client) Nodes() int

func (*Client) Profile

func (c *Client) Profile() client.UserProfile

func (*Client) RequestProfile

func (c *Client) RequestProfile(dst utils.NodeID, f func(profile *client.UserProfile))

Requests a user profile to the destination node. If no response is received from the node, RequestProfile tries to load a profile from the cache.

func (*Client) Run

func (c *Client) Run()

Starts a mainloop in the current goroutine.

func (*Client) SendMessage

func (c *Client) SendMessage(dst utils.NodeID, msg client.ChatMessage)

Sends the given message to the destination node.

func (*Client) SetProfile

func (c *Client) SetProfile(profile client.UserProfile)

func (*Client) SetStatus

func (c *Client) SetStatus(status client.UserStatus)

func (*Client) Status

func (c *Client) Status() client.UserStatus

func (*Client) UnmarshalCache

func (c *Client) UnmarshalCache(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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