xrootd

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: BSD-3-Clause Imports: 45 Imported by: 5

Documentation

Overview

Package xrootd implements the XRootD protocol from

http://xrootd.org

Package xrootd provides a Client and a Server.

The NewClient function connects to a server:

ctx := context.Background()

client, err := xrootd.NewClient(ctx, addr, username)
if err != nil {
	// handle error
}

// ...

if err := client.Close(); err != nil {
	// handle error
}

The NewServer function creates a server:

srv := xrootd.NewServer(xrootd.Default(), nil)
err := srv.Serve(listener)

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrServerClosed = errors.New("xrootd: server closed")

ErrServerClosed is returned by the Server's Serve method after a call to Shutdown.

Functions

This section is empty.

Types

type Client

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

A Client to xrootd server which allows to send requests and receive responses. Concurrent requests are supported. Zero value is invalid, Client should be instantiated using NewClient.

Example (Chmod)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

if err := client.FS().Chmod(ctx, "/tmp/test.txt", xrdfs.OpenModeOwnerRead|xrdfs.OpenModeOwnerWrite); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (Dirlist)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

entries, err := client.FS().Dirlist(ctx, "/tmp/dir1")
if err != nil {
	log.Fatal(err)
}
for _, entry := range entries {
	fmt.Printf("Name: %s, size: %d\n", entry.Name(), entry.Size())
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Name: file1.txt, size: 0
Example (Mkdir)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

if err := client.FS().Mkdir(ctx, "/tmp/testdir", xrdfs.OpenModeOwnerRead|xrdfs.OpenModeOwnerWrite); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (MkdirAll)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

if err := client.FS().MkdirAll(ctx, "/tmp/testdir/subdir", xrdfs.OpenModeOwnerRead|xrdfs.OpenModeOwnerWrite); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (Open)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

file, err := client.FS().Open(ctx, "/tmp/test.txt", xrdfs.OpenModeOwnerRead, xrdfs.OpenOptionsOpenRead)
if err != nil {
	log.Fatal(err)
}

if err := file.Close(ctx); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (Read)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

file, err := client.FS().Open(ctx, "/tmp/test.txt", xrdfs.OpenModeOwnerRead, xrdfs.OpenOptionsOpenRead)
if err != nil {
	log.Fatal(err)
}
defer file.Close(ctx)

data := make([]byte, 10)
n, err := file.ReadAt(data, 0)
if err != nil {
	log.Fatal(err)
}

data = data[:n]
fmt.Printf("%s\n", data)

if err := file.Close(ctx); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

test
Example (RemoveAll)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

if err := client.FS().RemoveAll(ctx, "/tmp/testdir"); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (RemoveDir)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

if err := client.FS().RemoveDir(ctx, "/tmp/testdir"); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (RemoveFile)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

if err := client.FS().RemoveFile(ctx, "/tmp/test.txt"); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (Rename)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

if err := client.FS().Rename(ctx, "/tmp/old.txt", "/tmp/new.txt"); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (Stat)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

info, err := client.FS().Stat(ctx, "/tmp/test.txt")
if err != nil {
	log.Fatal(err)
}

log.Printf("Name: %s, size: %d", info.Name(), info.Size())

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (Truncate)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

if err := client.FS().Truncate(ctx, "/tmp/test.txt", 10); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (VirtualStat)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

info, err := client.FS().VirtualStat(ctx, "/tmp/")
if err != nil {
	log.Fatal(err)
}

log.Printf("RW: %d%% is free", info.FreeRW)

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

Example (Write)
ctx := context.Background()
const username = "gopher"
client, err := NewClient(ctx, "ccxrootdgotest.in2p3.fr:9001", username)
if err != nil {
	log.Fatal(err)
}
defer client.Close()

file, err := client.FS().Open(ctx, "/tmp/test.txt", xrdfs.OpenModeOwnerRead|xrdfs.OpenModeOwnerWrite, xrdfs.OpenOptionsOpenUpdate|xrdfs.OpenOptionsNew)
if err != nil {
	log.Fatal(err)
}
defer file.Close(ctx)

if _, err := file.WriteAt([]byte("test"), 0); err != nil {
	log.Fatal(err)
}

if err := file.Sync(ctx); err != nil {
	log.Fatal(err)
}

if err := file.Close(ctx); err != nil {
	log.Fatal(err)
}

if err := client.Close(); err != nil {
	log.Fatal(err)
}
Output:

func NewClient

func NewClient(ctx context.Context, address string, username string, opts ...Option) (*Client, error)

NewClient creates a new xrootd client that connects to the given address using username. Options opts configure the client and are applied in the order they were specified. When the context expires, a response handling is stopped, however, it is necessary to call Cancel to correctly free resources.

func (*Client) Close

func (client *Client) Close() error

Close closes the connection. Any blocked operation will be unblocked and return error.

func (*Client) FS

func (cli *Client) FS() xrdfs.FileSystem

FS returns a xrdfs.FileSystem which uses this client to make requests.

func (*Client) Send

func (client *Client) Send(ctx context.Context, resp xrdproto.Response, req xrdproto.Request) (string, error)

Send sends the request to the server and stores the response inside the resp. If the resp is nil, then no response is stored. Send returns a session id which identifies the server that provided response.

type ErrorHandler

type ErrorHandler func(error)

ErrorHandler is the function which handles occurred error (e.g. logs it).

type Handler

type Handler interface {
	// Handshake handles the XRootD handshake: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248784.
	Handshake() (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Login handles the XRootD login request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248819.
	Login(sessionID [16]byte, request *login.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Protocol handles the XRootD protocol request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248827.
	Protocol(sessionID [16]byte, request *protocol.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Ping handles the XRootD ping request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248825.
	Ping(sessionID [16]byte, request *ping.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Dirlist handles the XRootD dirlist request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248815.
	Dirlist(sessionID [16]byte, request *dirlist.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// CloseSession handles the aborting of user session. This can be used to free some user-related data.
	CloseSession(sessionID [16]byte) error

	// Open handles the XRootD open request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248823.
	Open(sessionID [16]byte, request *open.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Close handles the XRootD close request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248813.
	Close(sessionID [16]byte, request *xrdclose.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Read handles the XRootD read request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248841.
	Read(sessionID [16]byte, request *read.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Write handles the XRootD write request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248855.
	Write(sessionID [16]byte, request *write.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Stat handles the XRootD stat request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248850.
	Stat(sessionID [16]byte, request *stat.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Sync handles the XRootD sync request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248852.
	Sync(sessionID [16]byte, request *sync.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Truncate handles the XRootD truncate request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248853.
	Truncate(sessionID [16]byte, request *truncate.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Rename handles the XRootD mv request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248822.
	Rename(sessionID [16]byte, request *mv.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Mkdir handles the XRootD mkdir request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248821.
	Mkdir(sessionID [16]byte, request *mkdir.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// Remove handles the XRootD rm request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248843.
	Remove(sessionID [16]byte, request *rm.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)

	// RemoveDir handles the XRootD rmdir request: http://xrootd.org/doc/dev45/XRdv310.htm#_Toc464248844.
	RemoveDir(sessionID [16]byte, request *rmdir.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus)
}

Handler provides a high-level API for the XRootD server. The Handler receives a parsed request and returns a response together with the status that will be send via Server to the client.

func Default

func Default() Handler

Default returns the defaultHandler implementing Handler with some general functionality added. Any unimplemented request returns InvalidRequest error.

func NewFSHandler

func NewFSHandler(basePath string) Handler

NewFSHandler creates a Handler that passes requests to the backing filesystem at basePath.

type Option

type Option func(*Client) error

Option configures an XRootD client.

func WithAuth

func WithAuth(a auth.Auther) Option

WithAuth adds an authentication mechanism to the XRootD client. If an authentication mechanism was already registered for that provider, it will be silently replaced.

type Server

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

Server implements the XRootD server following protocol from http://xrootd.org. The Server uses a Handler to handle incoming requests. To listen for incoming connections, Serve method must be called. It is possible to configure to listen on several ports simultaneously by calling Serve with different net.Listeners.

Example
package main

import (
	"log"
	"net"

	"go-hep.org/x/hep/xrootd"
)

func main() {
	addr := "0.0.0.0:1094"
	listener, err := net.Listen("tcp", addr)
	if err != nil {
		log.Fatalf("could not listen on %q: %v", addr, err)
	}

	srv := xrootd.NewServer(xrootd.Default(), func(err error) {
		log.Printf("an error occured: %v", err)
	})

	log.Printf("listening on %v...", listener.Addr())

	if err = srv.Serve(listener); err != nil {
		log.Fatalf("could not serve: %v", err)
	}
}
Output:

func NewServer

func NewServer(handler Handler, errorHandler ErrorHandler) *Server

NewServer creates a XRootD server which uses specified handler to handle requests and errorHandler to handle errors. If the errorHandler is nil, then a default error handler is used that does nothing.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call s.handler to handle them.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown stops Server and closes all listeners and active connections. Shutdown returns the first non nil error while closing listeners and connections.

Directories

Path Synopsis
cmd
xrd-client
Command xrd-client provides access to data hosted on XRootD clusters.
Command xrd-client provides access to data hosted on XRootD clusters.
xrd-cp
Command xrd-cp copies files and directories from a remote xrootd server to local storage.
Command xrd-cp copies files and directories from a remote xrootd server to local storage.
xrd-ls
Command xrd-ls lists directory contents on a remote xrootd server.
Command xrd-ls lists directory contents on a remote xrootd server.
xrd-srv
Command xrd-srv serves data from a local filesystem over the XRootD protocol.
Command xrd-srv serves data from a local filesystem over the XRootD protocol.
internal
mux
Package mux implements the multiplexer that manages access to and writes data to the channels by corresponding StreamID from xrootd protocol specification.
Package mux implements the multiplexer that manages access to and writes data to the channels by corresponding StreamID from xrootd protocol specification.
Package xrdfs contains structures representing the XRootD-based filesystem.
Package xrdfs contains structures representing the XRootD-based filesystem.
Package xrdio provides a File type that implements various interfaces from the io package.
Package xrdio provides a File type that implements various interfaces from the io package.
Package protocol contains the XRootD protocol specific types and methods to handle them, such as marshalling and unmarshalling requests.
Package protocol contains the XRootD protocol specific types and methods to handle them, such as marshalling and unmarshalling requests.
admin
Package admin contains the types related to the admin request.
Package admin contains the types related to the admin request.
auth
Package auth contains the structures describing auth request.
Package auth contains the structures describing auth request.
auth/host
Package host contains the implementation for the "host" security provider.
Package host contains the implementation for the "host" security provider.
auth/krb5
Package krb5 contains the implementation of krb5 (Kerberos) security provider.
Package krb5 contains the implementation of krb5 (Kerberos) security provider.
auth/unix
Package unix contains the implementation of unix security provider.
Package unix contains the implementation of unix security provider.
bind
Package bind contains the structures describing bind request and response.
Package bind contains the structures describing bind request and response.
chmod
Package chmod contains the structures describing chmod request.
Package chmod contains the structures describing chmod request.
decrypt
Package decrypt contains the types related to the decrypt request.
Package decrypt contains the types related to the decrypt request.
dirlist
Package dirlist contains the structures describing request and response for dirlist request used to obtain the contents of a directory.
Package dirlist contains the structures describing request and response for dirlist request used to obtain the contents of a directory.
endsess
Package endsess contains the types related to the endsess request.
Package endsess contains the types related to the endsess request.
handshake
Package handshake contains the structures describing request and response for handshake request (see XRootD specification).
Package handshake contains the structures describing request and response for handshake request (see XRootD specification).
locate
Package locate contains the types related to the locate request.
Package locate contains the types related to the locate request.
login
Package login contains the structures describing request and response for login request.
Package login contains the structures describing request and response for login request.
mkdir
Package mkdir contains the structures describing mkdir request.
Package mkdir contains the structures describing mkdir request.
mv
Package mv contains the structures describing mv request.
Package mv contains the structures describing mv request.
open
Package open contains the structures describing request and response for open request.
Package open contains the structures describing request and response for open request.
ping
Package ping contains the structures describing ping request.
Package ping contains the structures describing ping request.
prepare
Package prepare contains the types related to the prepare request.
Package prepare contains the types related to the prepare request.
protocol
Package protocol contains the structures describing request and response for protocol request (see XRootD specification).
Package protocol contains the structures describing request and response for protocol request (see XRootD specification).
query
Package query contains the types related to the query request.
Package query contains the types related to the query request.
read
Package read contains the structures describing request and response for read request.
Package read contains the structures describing request and response for read request.
rm
Package rm contains the structures describing rm request.
Package rm contains the structures describing rm request.
rmdir
Package rmdir contains the structures describing rmdir request.
Package rmdir contains the structures describing rmdir request.
signing
Package signing contains implementation of a way to check if request should be signed according to XRootD protocol specification v.
Package signing contains implementation of a way to check if request should be signed according to XRootD protocol specification v.
sigver
Package sigver contains the structures describing sigver request.
Package sigver contains the structures describing sigver request.
stat
Package stat contains the structures describing request and response for stat request.
Package stat contains the structures describing request and response for stat request.
statx
Package statx contains the structures describing request and response for statx request.
Package statx contains the structures describing request and response for statx request.
sync
Package sync contains the structures describing sync request.
Package sync contains the structures describing sync request.
truncate
Package truncate contains the structures describing truncate request.
Package truncate contains the structures describing truncate request.
verifyw
Package verifyw contains the structures describing verifyw request.
Package verifyw contains the structures describing verifyw request.
write
Package write contains the structures describing write request.
Package write contains the structures describing write request.
xrdclose
Package xrdclose contains the structures describing request and response for close request.
Package xrdclose contains the structures describing request and response for close request.

Jump to

Keyboard shortcuts

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