xdrrpc

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

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

Go to latest
Published: Dec 28, 2019 License: MIT Imports: 9 Imported by: 0

README

xdrrpc (simple-nfs-server) - nfs server the easy way

Overview

simple-nfs-server is an example nfs server implementation that serves files from memory. xdrrpc is a golang library to create XDRRPC services also known as SUNRPC or ONCRPC (RFC 5531). Both are written in pure go, without using rpcgen toolchain (Sun Microsystems ONC RPC generator). xdrrpc conforms to golang net/rpc ServerCodec interface. API documentation for xdrrpc can be found in GoDoc.

Installation

$ go get -u github.com/dzeromsk/xdrrpc/...

This will make the simple-nfs-server tool available in ${GOPATH}/bin, which by default means ~/go/bin.

Usage

simple-nfs-server serves all files from memory with limited support for attributes.

Usage of simple-nfs-server:
  -debug
        Enable debug prints
  -listen string
        Server listen address (default ":12049")

Example

Start simple-nfs-server

$ simple-nfs-server --debug -listen :12049

Mount on the client using fixed protocol (tcp), port (12049) and any mount point on localhost:

$ sudo mount -vvv -o nfsvers=3,proto=tcp,port=12049,mountvers=3,mountport=12049,mountproto=tcp 127.0.0.1:/ /mnt/example

Low level usage of xdrrpc package

import (
  "net/rpc"
  "github.com/dzeromsk/xdrrpc"
)

func init() {
  xdrrpc.Register(100005, 3, 0, "Mount", "Null")
}

type Mount struct {}

func (m *Mount) Null(args *mount.NullArgs, res *mount.NullRes) error {
	return nil
}

func main() {
	rpc.Register(mount)
	ln, _ := net.Listen("tcp", *listen)
	for {
		conn, _ := ln.Accept()
		go xdrrpc.ServeConn(conn)
	}
}

For helpers like nfs.ServeMux usage please take a look at xdrrpc/nfs and xdrrpc/example/memfs packages. Skimming through RFC 1813 will help too.

Features

  • Simple.
  • Memory only.
  • Compatible with Linux kernel NFS Client.
  • Implements stdlib ServerCodec.

Downsides

  • Some features are missing.

Philosophy

xdrrpc conforms to golang net/rpc ServerCodec interface. At some point in future we should consider replacing net/rpc with custom RPC server implementation.

I made this to debug Linux NFS Client attribute caching behavior at work. Feel free to fork it.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug = false
View Source
var DefaultMap sync.Map

Functions

func NewServerCodec

func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec

NewServerCodec returns a new rpc.ServerCodec using JSON-RPC on conn.

func Register

func Register(program, version, procedure uint32, service, method string)

func ServeConn

func ServeConn(conn io.ReadWriteCloser)

ServeConn runs the XRP-RPC server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement.

Types

type AcceptStat

type AcceptStat int32
const (
	Success      AcceptStat = iota // RPC executed successfully
	ProgUnavail                    // Remote hasn't exported the program
	ProgMismatch                   // Remote can't support version number
	ProcUnavail                    // Program can't support procedure
	GarbageArgs                    // Procedure can't decode params
	SystemError                    // Other errors
)

type AuthFlavor

type AuthFlavor int32

type MessageType

type MessageType int32
const (
	Call  MessageType = 0
	Reply MessageType = 1
)

type OpaqueAuth

type OpaqueAuth struct {
	Flavor AuthFlavor
	Body   []byte
}

OpaqueAuth is a structure with AuthFlavor enumeration followed by up to 400 bytes that are opaque to (uninterpreted by) the RPC protocol implementation.

type ReplyStat

type ReplyStat int32
const (
	MessageAccepted ReplyStat = 0
	MessageDenied   ReplyStat = 1
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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