ipmsg

package module
v0.0.0-...-28d9cee Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2015 License: MIT Imports: 7 Imported by: 0

README

go-ipmsg

IPMSG protocol implementation for golang

To install, simply issue a go get:

go get github.com/masanorih/go-ipmsg

By default importing github.com/masanorih/go-ipmsg will import package ipmsg

import (
    "log"
    "github.com/masanorih/go-ipmsg"
)

conf := ipmsg.NewIPMSGConf()
ipmsg, err := ipmsg.NewIPMSG(conf)
if err != nil {
   log.Fatalf("Failed to start ipmsg: %v", err)
}
defer ipmsg.Close()

go-ipmsg is a port of Net::IPMessenger

When you create a new struct via NewIPMSG() a new ipmsg instance is automatically setup and launched. Don't forget to call Close() on this struct to close the ipmsg server

If you want to customize the configuration, create a new config and set each field on the struct:


conf := ipmsg.NewIPMSGConf()
conf.Port = 12425

// Starts ipmsg listening on port 12425
ipmsg, err := ipmsg.NewIPMSG(conf)

TODO

add encription support

Documentation

Index

Constants

View Source
const (
	DefaultPort int = 2425
	Buflen      int = 65535
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientData

type ClientData struct {
	Version   int
	PacketNum int
	User      string
	Host      string
	Command   Command
	Option    string
	Nick      string
	Group     string
	Addr      *net.UDPAddr
	ListAddr  string
	Time      time.Time
	PubKey    string
	Encrypt   bool
	Attach    bool
}

func NewClientData

func NewClientData(msg string, addr *net.UDPAddr) *ClientData

func (ClientData) Key

func (c ClientData) Key() string

func (ClientData) NickName

func (c ClientData) NickName() string

func (*ClientData) Parse

func (c *ClientData) Parse(msg string)

func (*ClientData) String

func (c *ClientData) String() string

func (*ClientData) UpdateNick

func (c *ClientData) UpdateNick()

type Command

type Command int
const (
	// COMMAND
	NOOPERATION     Command = 0x00000000
	BR_ENTRY        Command = 0x00000001
	BR_EXIT         Command = 0x00000002
	ANSENTRY        Command = 0x00000003
	BR_ABSENCE      Command = 0x00000004
	BR_ISGETLIST    Command = 0x00000010
	OKGETLIST       Command = 0x00000011
	GETLIST         Command = 0x00000012
	ANSLIST         Command = 0x00000013
	BR_ISGETLIST2   Command = 0x00000018
	SENDMSG         Command = 0x00000020
	RECVMSG         Command = 0x00000021
	READMSG         Command = 0x00000030
	DELMSG          Command = 0x00000031
	ANSREADMSG      Command = 0x00000032
	GETINFO         Command = 0x00000040
	SENDINFO        Command = 0x00000041
	GETABSENCEINFO  Command = 0x00000050
	SENDABSENCEINFO Command = 0x00000051
	GETFILEDAT      Command = 0x00000060
	RELEASEFIL      Command = 0x00000061
	GETDIRFILE      Command = 0x00000062
	GETPUBKEY       Command = 0x00000072
	ANSPUBKEY       Command = 0x00000073
	// MODE
	MODE Command = 0x000000ff
	// OPTION
	//ABSENCE    Command = 0x00000100
	//SERVER     Command = 0x00000200
	//DIALUP     Command = 0x00010000
	SENDCHECK  Command = 0x00000100
	SECRET     Command = 0x00000200
	BROADCAST  Command = 0x00000400
	MULTICAST  Command = 0x00000800
	NOPOPUP    Command = 0x00001000
	AUTORET    Command = 0x00002000
	RETRY      Command = 0x00004000
	PASSWORD   Command = 0x00008000
	NOLOG      Command = 0x00020000
	NEWMUTI    Command = 0x00040000
	NOADDLIST  Command = 0x00080000
	READCHECK  Command = 0x00100000
	FILEATTACH Command = 0x00200000
	ENCRYPT    Command = 0x00400000
)

func (Command) Get

func (msg Command) Get(flg Command) bool

func (Command) Mode

func (msg Command) Mode() Command

func (Command) ModeName

func (msg Command) ModeName() string

func (*Command) SetOpt

func (msg *Command) SetOpt(flg Command)

func (Command) String

func (i Command) String() string

type EvFunc

type EvFunc func(cd *ClientData, ipmsg *IPMSG) error

type EventHandler

type EventHandler struct {
	String   string
	Handlers map[Command]EvFunc
	Debug    bool
}

func NewEventHandler

func NewEventHandler() *EventHandler

func (*EventHandler) Regist

func (ev *EventHandler) Regist(cmd Command, evfunc EvFunc)

func (*EventHandler) Run

func (ev *EventHandler) Run(cd *ClientData, ipmsg *IPMSG) error

func (*EventHandler) RunDebug

func (ev *EventHandler) RunDebug(cd *ClientData)

type IPMSG

type IPMSG struct {
	ClientData ClientData
	Conn       *net.UDPConn
	Conf       *IPMSGConfig
	Handlers   []*EventHandler
	PacketNum  int
}

func NewIPMSG

func NewIPMSG(conf *IPMSGConfig) (*IPMSG, error)

func (*IPMSG) AddEventHandler

func (ipmsg *IPMSG) AddEventHandler(ev *EventHandler)

func (*IPMSG) BuildData

func (ipmsg *IPMSG) BuildData(addr *net.UDPAddr, msg string, cmd Command) *ClientData

func (*IPMSG) Close

func (ipmsg *IPMSG) Close() error

func (*IPMSG) GetNewPacketNum

func (ipmsg *IPMSG) GetNewPacketNum() int

func (*IPMSG) Myinfo

func (ipmsg *IPMSG) Myinfo() string

func (*IPMSG) RecvMSG

func (ipmsg *IPMSG) RecvMSG() (*ClientData, error)

func (*IPMSG) SendMSG

func (ipmsg *IPMSG) SendMSG(addr *net.UDPAddr, msg string, cmd Command) error

func (*IPMSG) UDPAddr

func (ipmsg *IPMSG) UDPAddr() (*net.UDPAddr, error)

convert net.Addr to net.UDPAddr

type IPMSGConfig

type IPMSGConfig struct {
	NickName  string
	GroupName string
	UserName  string
	HostName  string
	Port      int
	Local     string
}

func NewIPMSGConf

func NewIPMSGConf() *IPMSGConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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