robustsession

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: BSD-3-Clause Imports: 20 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.10"

Variables

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

Functions

This section is empty.

Types

type Network added in v1.9.0

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

A Network is a collection of RobustIRC nodes forming a RobustIRC network. This type is only exported so that you can expose internal network state for debugging via CopyNetworks().

func CopyNetworks added in v1.9.0

func CopyNetworks() []*Network

CopyNetworks returns a copy of the currently in-use RobustIRC networks for debugging.

func (*Network) String added in v1.9.0

func (n *Network) String() string

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

	// Format string for unavailability messages to inject.
	UnavailableMessageFormat string

	// RobustPing messages contain the current list of server addresses of the network,
	// which robustsession uses to keep the list of servers up to date
	// without having to periodically re-resolve the DNS names (--network flag).
	// If IgnoreServerListUpdates is true, robustsession will ignore the list of servers.
	// This is useful when working with different names on client and server,
	// for example when the client connects via a port forwarding.
	IgnoreServerListUpdates bool
	// 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.

func (*RobustSession) String added in v1.9.0

func (s *RobustSession) String() string

Jump to

Keyboard shortcuts

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