robustsession

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2018 License: BSD-3-Clause Imports: 18 Imported by: 1

Documentation

Overview

robustsession represents a RobustIRC session and handles all communication to the RobustIRC network.

Index

Examples

Constants

View Source
const Version = "RobustIRC Bridge v1.7"

Variables

View Source
var (
	NoSuchSession = errors.New("No such RobustIRC session (killed by the network?)")
)

Functions

func DeadlineConnDialer

func DeadlineConnDialer(dialTimeout, keepalivePeriod, timeout time.Duration) func(string, string) (net.Conn, error)

DeadlineConnDialer returns a net.Dialer (actual interface type unused because it is not covered by go1) which wraps all net.Conns in a deadlineConn with the specified |timeout|, applied to both, Read and Write calls. The dialing itself must be done within |dialTimeout| and TCP keepalive is enabled (if compiled with go1.2+) with a period of |keepalivePeriod|.

func NewDeadlineConn

func NewDeadlineConn(conn net.Conn, timeout time.Duration) *deadlineConn

Types

type RobustSession

type RobustSession struct {
	IrcPrefix *irc.Prefix
	Messages  chan string
	Errors    chan error

	// ForwardedFor will be sent in all HTTP requests as X-Forwarded-For header
	// if non-empty.
	ForwardedFor string

	// BridgeAuth will be sent in all HTTP requests as X-Bridge-Auth header if
	// non-empty. See https://github.com/robustirc/robustirc/issues/122
	BridgeAuth string
	// contains filtered or unexported fields
}
Example
package main

import (
	"log"

	"github.com/robustirc/bridge/robustsession"
)

func main() {
	session, err := robustsession.Create("robustirc.net", "")
	if err != nil {
		log.Fatalf("Could not create robustsession: %v", err)
	}
	go func() {
		for msg := range session.Messages {
			log.Printf("<- %s\n", msg)
		}
	}()
	go func() {
		for err := range session.Errors {
			log.Fatalf("RobustSession error: %v", err)
		}
	}()

	input := []string{
		"NICK example",
		"USER docs * 0 :Example User",
		"JOIN #robustirc",
		"PRIVMSG #robustirc :trying out the example :)",
		"QUIT :woohoo",
		"PRIVMSG #robustirc :this will trigger an error",
	}
	for _, msg := range input {
		log.Printf("-> %s\n", msg)
		if err := session.PostMessage(msg); err != nil {
			log.Fatal(err)
		}
	}
}
Output:

func Create

func Create(network string, tlsCAFile string) (*RobustSession, error)

Create creates a new RobustIRC session. It resolves the given network name (e.g. "robustirc.net") to a set of servers by querying the _robustirc._tcp.<network> SRV record and sends the CreateSession request.

When err == nil, the caller MUST read the RobustSession.Messages and RobustSession.Errors channels.

tlsCAFile specifies the path to an x509 root certificate, which is mostly useful for testing. If empty, the system CA store will be used (recommended).

func (*RobustSession) Delete

func (s *RobustSession) Delete(quitmessage string) error

Delete sends a delete request for this session on the server.

This session MUST not be used after this method returns. Even if the delete request did not succeed, the session is deleted from the client’s point of view.

func (*RobustSession) PostMessage

func (s *RobustSession) PostMessage(message string) error

PostMessage posts the given IRC message. It will retry automatically on transient errors, and only return an error when the network returned a permanent error, such as NoSuchSession.

The RobustIRC protocol dictates that you must not try to send more than one message at any given point in time, and PostMessage enforces this by using a mutex.

func (*RobustSession) SessionId

func (s *RobustSession) SessionId() string

SessionId returns a string that identifies the session. It should be used in log messages to identify sessions.

Jump to

Keyboard shortcuts

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