pesit

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 22 Imported by: 1

README

PeSIT

This library is an implementation of the PeSIT version E protocol in Go.

It provides a high level API of a client and a server.

import: code.waarp.fr/lib/pesit

Contents

[[TOC]]

Pesit Protocol

Pesit is a File Transfer Protocol. Unlike the simple protocols FTP and SFTP, PeSIT was designed from the ground up with a focus on control and security in the file transfer process.

PeSIT’s file data flow control smoothly shares CPU and bandwidth resources among file transfers during heavy workloads. Transfer processes are tracked across the network using unique identifiers. Transfers can be triggered and executed with differently assigned priority levels. Neither the filename nor its location on the host or destination filesystem is ever shared across the network.

  • writing of a distant file
  • reading a distant fife
  • checkpointing during a transfer
  • resuming a interrupted transfer from a negotiated restart point
  • resynchronising during a transfer
  • suspension of a transfer
  • securitize a transfer
  • data compression
  • error control

Features

  • File Transfer (send and receive)
  • Checkpointing
  • Transfer recovery

Roadmap

See STATUS.md

Getting Started

Get the Code
go get code.waarp.fr/waarp-r66/r66
Import the Library
import "code.waarp.fr/lib/pesit"

Run the Tests

go test ./...

Usage example

See the examples folder.

License

TBD

Documentation

Overview

Package pesit provides a high level client and serverto communicate with other systems using the PeSIT protocol.

Index

Constants

View Source
const (
	// CodeSuccess Success means no error.
	CodeSuccess = diagnostics.CodeSuccess

	// CodeTransmissionError Transmission error.
	CodeTransmissionError = diagnostics.CodeTransmissionError

	// CodeInsufficientCharacteristics Insufficient file characteristics.
	CodeInsufficientCharacteristics = diagnostics.CodeInsufficientCharacteristics

	// CodeSystemResourcesInsufficient System resources temporarily insufficient.
	CodeSystemResourcesInsufficient = diagnostics.CodeSystemResourcesInsufficient

	// CodeUserResourcesInsufficient User resources temporarily insufficient.
	CodeUserResourcesInsufficient = diagnostics.CodeUserResourcesInsufficient

	// CodeLowPriorityTransfer Low Priority transfer.
	CodeLowPriorityTransfer = diagnostics.CodeLowPriorityTransfer

	// CodeFileAlreadyExists File already exists.
	CodeFileAlreadyExists = diagnostics.CodeFileAlreadyExists

	// CodeFileNotExists File does not exists.
	CodeFileNotExists = diagnostics.CodeFileNotExists

	// CodeInsufficientDiskSpace File reception would cause disk quota overflow.
	CodeInsufficientDiskSpace = diagnostics.CodeInsufficientDiskSpace

	// CodeFileBusy File busy.
	CodeFileBusy = diagnostics.CodeFileBusy

	// CodeFileTooOld File too old (prior to D-2 in SIT terms).
	CodeFileTooOld = diagnostics.CodeFileNotOld

	// CodeMessageTypeRefused Message type not accepted by the installation referred to.
	CodeMessageTypeRefused = diagnostics.CodeMessageTypeRefused

	// CodePresentationContextNegotiationError Presentation context negotiation failure.
	CodePresentationContextNegotiationError = diagnostics.CodePresentationContextNegotiationError

	// CodeFileOpenError File cannot be opened.
	CodeFileOpenError = diagnostics.CodeFileOpenError

	// CodeFileCloseError Normal file closure impossible.
	CodeFileCloseError = diagnostics.CodeFileCloseError

	// CodeUnresolvableIO Unresolvable I/O error.
	CodeUnresolvableIO = diagnostics.CodeUnresolvableIO

	// CodeRestartNegotiationError Restart negotiation failure.
	CodeRestartNegotiationError = diagnostics.CodeRestartNegotiationError

	// CodeInternalError Internal system error.
	CodeInternalError = diagnostics.CodeInternalError

	// CodeVolontaryTermination Voluntary abrupt termination.
	CodeVolontaryTermination = diagnostics.CodeVolontaryTermination

	// CodeTooManyAcknowledgedCheckpoints Too many acknowledged checkpoint.
	CodeTooManyAcknowledgedCheckpoints = diagnostics.CodeTooManyUnacknowledgedCheckpoints

	// CodeRestartImpossible Restart impossible.
	CodeRestartImpossible = diagnostics.CodeRestartImpossible

	// CodeFileSpaceOverflow File space overflow.
	CodeFileSpaceOverflow = diagnostics.CodeFileSpaceOverflow

	// CodeExcedeedLength Article length exceeds expected length.
	CodeExcedeedLength = diagnostics.CodeExcedeedLength

	// CodeEndTransmissionTimeoutExpired End of transmission time-out expired.
	CodeEndTransmissionTimeoutExpired = diagnostics.CodeEndTransmissionTimeoutExpired

	// CodeExcessDataBetweenCheckpoints Excess data between checkpoints.
	CodeExcessDataBetweenCheckpoints = diagnostics.CodeExcessDataBetweenCheckpoints

	// CodeAbnormalEOT Abnormal end of transfer.
	CodeAbnormalEOT = diagnostics.CodeAbnormalEOT

	// CodeFileSizeExceeded  The size of the file transmitted exceeds the size given in F.CREATE.
	CodeFileSizeExceeded = diagnostics.CodeFileSizeExceeded

	// CodeApplicationCongestion Congestion in the station application software:
	// the file has been correctly received but SCRS cannot pass it on the application software.
	CodeApplicationCongestion = diagnostics.CodeApplicationCongestion

	// CodeTransferRefused Transfer refused.
	CodeTransferRefused = diagnostics.CodeTransferRefused

	// CodeOtherTransferError Other.
	CodeOtherTransferError = diagnostics.CodeOtherTransferError

	// CodeNetworkSaturation Logical "communication system" saturation.
	CodeNetworkSaturation = diagnostics.CodeNetworkSaturation

	// CodeUnknownIdentification Unknown called party identification.
	CodeUnknownIdentification = diagnostics.CodeUnknownIdentification

	// CodeNotLinkedToSSAP Called party not connected to SSAP.
	CodeNotLinkedToSSAP = diagnostics.CodeNotLinkedToSSAP

	// CodeRemoteNetworkSaturation Distant "communication system" saturated (too many connections).
	CodeRemoteNetworkSaturation = diagnostics.CodeRemoteNetworkSaturation

	// CodeUnauthorizedCaller Unauthorized caller identification (security).
	CodeUnauthorizedCaller = diagnostics.CodeUnauthorizedCaller

	// CodeFileSelectionNegotiationError Negotiation failure: SELECT.
	CodeFileSelectionNegotiationError = diagnostics.CodeFileSelectionNegotiationError

	// CodeResynNegotiationError Negotiation failure: RESYN.
	CodeResynNegotiationError = diagnostics.CodeResynNegotiationError

	// CodeSyncNegotiationError Negotiation failure: SYNC.
	CodeSyncNegotiationError = diagnostics.CodeSyncNegotiationError

	// CodeUnsupportedVersion Version number not supported.
	CodeUnsupportedVersion = diagnostics.CodeUnsupportedVersion

	// CodeTooManyConnections Too many connections already open for a processing center.
	CodeTooManyConnections = diagnostics.CodeTooManyConnections

	// CodeNetworkError Network incident.
	CodeNetworkError = diagnostics.CodeNetworkError

	// CodeRemoteProtocolError Distant PeSIT protocol error.
	CodeRemoteProtocolError = diagnostics.CodeRemoteProtocolError

	// CodeUserServiceTermination Service termination requested by the user.
	CodeUserServiceTermination = diagnostics.CodeUserServiceTermination

	// CodeConnectedTimeoutExpired Connection terminated after time-out Td.
	CodeConnectedTimeoutExpired = diagnostics.CodeConnectedTimeoutExpired

	// CodeConnectionSlotFreed Unused connection broken to accept a new connection.
	CodeConnectionSlotFreed = diagnostics.CodeConnectionSlotFreed

	// CodeNegotiationError Negotiation failure.
	CodeNegotiationError = diagnostics.CodeNegotiationError

	// CodeAdminRequest Connection broken by administrative request.
	CodeAdminRequest = diagnostics.CodeAdminRequest

	// CodeTimeoutExpired Time-out expired.
	CodeTimeoutExpired = diagnostics.CodeTimeoutExpired

	// CodeParameterError Mandatory parameter missing or illegal parameter content.
	CodeParameterError = diagnostics.CodeParameterError

	// CodeInvalidCount Byte count or article count incorrect.
	CodeInvalidCount = diagnostics.CodeInvalidCount

	// CodeTooManyRetries Excessive number of retries during the transfer.
	CodeTooManyRetries = diagnostics.CodeTooManyRetries

	// CodeCallBackupNumber Call the back-up number.
	CodeCallBackupNumber = diagnostics.CodeCallBackupNumber

	// CodeTryLater Call back later.
	CodeTryLater = diagnostics.CodeTryLater

	// CodeOtherConnectionError Other.
	CodeOtherConnectionError = diagnostics.CodeOtherConnectionError
)
View Source
const (
	MaximumArticleSize uint16 = 0xFFF0
	MaximumMessageSize uint16 = 0xFFF0
)
View Source
const CheckpointDisabled = 0

CheckpointDisabled is the zero value for the checkpoint size property. It can be used to explicitly indicate that the checkpoints are disabled for the connection.

Variables

View Source
var (
	ErrUnknownFpduGroup            = fpdus.ErrInvalidFpduID
	ErrInvalidFpduID               = fpdus.ErrInvalidFpduID
	ErrUnknownFPDU           error = errors.New("unknown fpdu")
	ErrUnknownPrimitive      error = errors.New("unknown primitive")
	ErrInvalidFPDUSize       error = errors.New("invalid FPDU size")
	ErrMissingMandatoryParam error = errors.New("missing mandatory param")
)
View Source
var (
	// ErrInvalidWrite means that a transfer object was not in a state where Write
	// can be called.
	ErrInvalidWrite = errors.New("invalid write operation")

	// ErrInvalidRead means that a transfer object was not in a state where Write
	// can be called.
	ErrInvalidRead = errors.New("invalid read operation")

	// ErrStartDataTransfer means that StartDataTransfer has been called on a
	// transfer, but all the conditions needed for the call to succeed are not
	// met.
	ErrStartDataTransfer = errors.New("invalid StartDataTransfer operation")

	// ErrTransferAlreadyRegistered is returned when a transfer that has already
	// been registered is registered again.
	ErrTransferAlreadyRegistered = errors.New("transfer alredy registered")

	// ErrTransferInvalid is returned when a transfer is registered, but it
	// misses some properties.
	ErrTransferInvalid = errors.New("invalid transfer")

	// ErrInvalidRestart indicates that an invalid transfer restart has been
	// requested.
	ErrInvalidRestart = errors.New("invalid restart")

	ErrInvalidOperation = errors.New("invalid operation")
)
View Source
var (
	ErrNoMoreArticle         error = errors.New("no more article")
	ErrInvalidReadOperation  error = errors.New("invalid read operation")
	ErrInvalidWriteMode      error = errors.New("invalid write mode")
	ErrInvalidWriteOperation error = errors.New("invalid write operation")
)
View Source
var (

	// ErrTransferSizeMismatch is returned when the remote advertised a incorrect
	// number of Bytes or Articles transferred.
	ErrTransferSizeMismatch = diagnostics.Diagnostic{
		Code:    CodeInvalidCount,
		Message: "transfer size mismatch",
	}
)

Functions

func IsError

func IsError(err error) bool

Types

type AccessType

type AccessType uint8

AccessType indicated the type of access allowed during a connection.

const (
	AccessWrite AccessType = iota
	AccessRead
	AccessReadWrite
)

func (AccessType) String

func (i AccessType) String() string

type ArticleFormat

type ArticleFormat uint8

ArticleFormat indicates whether an article has a fixed or a variable length.

const (
	FormatFixed    ArticleFormat = 0
	FormatVariable ArticleFormat = 0x80
)

func (ArticleFormat) String

func (i ArticleFormat) String() string

type Attributes

type Attributes uint8

Attributes is a bitmask with one bit for each attribute category: Logical, physical and historical.

const (
	AttrLogical Attributes = 1 << iota
	AttrPhysical
	AttrHistorical
)

type Client

type Client struct {

	// Log can be used to print debugging messages.
	Logger       *log.Logger
	NetworkTrace *log.Logger
	// contains filtered or unexported fields
}

Client is a fully functional client.

A PeSIT client can only do a single transfer at once.

A client has internal state (such as a TCP connection), and should be reused as much as possible.

Connections with a server are automatically attempted when a transfer is run. If no connection is already established, or if the previously connection has timed out, a new connection will be attempted.

func NewClient

func NewClient(login, password, serverLogin string) *Client

NewClient initializes a new client for the given address.

The login is the identifier of the client. It is sent to the server along with the password to be authentified.

It **must** be shorter than 24 bytes. It will be truncated if longer.

The password is the password of the client. It **must** be shorter than 8 bytes. Longer values will be truncated.

func (*Client) Abort

func (c *Client) Abort(srcErr error)

Abort sends the abort signal to the server before interrupting abruptly and unconditionally the connection. It can be called anytime. An error can be given to indicate why Abort has been called. If the error has not the `Error` type, it will be converted to one before it is sent to the server. If the error is nil, a generic one is sent to the server.

func (*Client) AccessType

func (c *Client) AccessType() AccessType

func (*Client) AllowCheckpoints

func (c *Client) AllowCheckpoints(size uint16, window uint8) bool

AllowCheckpoints enables the checkpointing service for a client. It can only be changed if the client is not connected.

The argument size defines the size of transmitted data between two checkpoints. The argument window defines the allowed number of sequential non acknowledged checkpoints. Beyond that window, data transfer is stopped.

To disable checkpointing, set size to CheckpointDisabled. If checkpointing is disabled, set restart option to false.

The return value indicates if the value has been changed or not.

func (*Client) AllowRestart

func (c *Client) AllowRestart(val bool) bool

AllowRestart enables the checkpointing service for a client. It can only be changed if the client is not connected. If no checkpointing has been set, sets a default checkpointing. The return value indicates if the value has been changed or not.

func (*Client) CheckpointSize

func (c *Client) CheckpointSize() uint16

CheckpointSize returns the saze of data transmitted between two checkpoints.

func (*Client) CheckpointWindow

func (c *Client) CheckpointWindow() uint8

CheckpointWindow returns the allowed number of sequential non-acknowledged checkpoints.

func (*Client) ClientLogin

func (c *Client) ClientLogin() string

ClientLogin returns the login used by the client to authenticate toward the server.

func (*Client) ClientPassword

func (c *Client) ClientPassword() string

ClientPassword returns the password used by the client to authenticate toward the server.

func (*Client) Close

func (c *Client) Close(cause error) error

Close disconnects the client from the partner.

If the connection is not established, it returns nothing.

If a transfer is still active Close will return ErrInvalidOperation.

After Close is called, the client can still be reused.

func (*Client) Connect

func (c *Client) Connect(conn net.Conn) (err error)

Connect establishes a connection with the server. If a connection is already established, it returns nothing.

func (*Client) Dial

func (c *Client) Dial(address string, tlsConfig *tls.Config) error

func (*Client) ForceClose

func (c *Client) ForceClose()

ForceClose interrupts abruptly and unconditionally the connection. It can be called anytime.

func (*Client) FreeText

func (c *Client) FreeText() string

func (*Client) HasCheckpoints

func (c *Client) HasCheckpoints() bool

HasCheckpoints returns true if checkpoints are enabled for the client, and false otherwise.

func (*Client) HasRestart

func (c *Client) HasRestart() bool

HasRestart returns true if restarts are enabled for the client, and false otherwise.

func (*Client) HasTransfer

func (c *Client) HasTransfer() bool

HasTransfer returns true if the client has an ongoing transfer.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if the client has an active connection to the server.

func (*Client) NewClientPassword

func (c *Client) NewClientPassword() string

NewClientPassword returns the password that will be used by the client for future authentication attempts toward the server.

func (*Client) NewServerPassword

func (c *Client) NewServerPassword() string

NewServerPassword returns the password that will be used by the server for future authentication attempts toward the client.

This should be used after Connect has successfully returned.

func (*Client) PreConnectLogin

func (c *Client) PreConnectLogin() string

PreConnectLogin returns the login used by the client for the preconnection exchange.

func (*Client) PreConnectPassword

func (c *Client) PreConnectPassword() string

PreConnectPassword returns the password used by the client for the preconnection exchange.

func (*Client) Profile

func (c *Client) Profile() Profile

Profile returns the PeSIT profile used by the client.

func (*Client) SelectFile

func (c *Client) SelectFile(t *ClientTransfer) error

SelectFile requests the server to select the transferred target file.

The transfer must be fully qualified (except for Compression and Recovery point) before calling this method. Once this function returns the Get function can be called to check the result of the negotiation.

If the client is not connected, SelectFile returns ErrInvalidOperation.

If any error occurring during the communication with the partner an error of type Diagnostic will be returned.

func (*Client) ServerLogin

func (c *Client) ServerLogin() string

ServerLogin returns the login used by the server to authenticate toward the client.

This should be used after Connect has successfully returned.

func (*Client) ServerPassword

func (c *Client) ServerPassword() string

ServerPassword returns the password used by the server to authenticate toward the client.

This should be used after Connect has successfully returned.

func (*Client) SetAccessType

func (c *Client) SetAccessType(a AccessType) bool

func (*Client) SetCFTCompatibilityUsage

func (c *Client) SetCFTCompatibilityUsage(usage bool) bool

func (*Client) SetCRCUsage

func (c *Client) SetCRCUsage(usage bool) bool

SetCRCUsage enables (or disables) the CRC service for a clinet. It can only be changed if the client is not connected.

The return value indicates if the value has been changed or not.

func (*Client) SetFreeText

func (c *Client) SetFreeText(f string) bool

func (*Client) SetNSDUUsage

func (c *Client) SetNSDUUsage(use bool) bool

func (*Client) SetNewClientPassword

func (c *Client) SetNewClientPassword(password string) bool

SetNewClientPassword sets the password that should will be used by the client for future authentication attempt toward the server.

The return value indicates if the value has been changed or not.

func (*Client) SetPreConnectLogin

func (c *Client) SetPreConnectLogin(login string) bool

SetPreConnectLogin set the login used by the client for the preconnection exchange. If the given login is longer than 8 char it will be trimmed down to 8 characters.

func (*Client) SetPreConnectPassword

func (c *Client) SetPreConnectPassword(password string) bool

SetPreConnectPassword set the password used by the client for the preconnection exchange. If the given login is longer than 8 char it will be trimmed down to 8 characters.

func (*Client) SetPreConnectionUsage

func (c *Client) SetPreConnectionUsage(use bool) bool

func (*Client) SetServerLogin

func (c *Client) SetServerLogin(login string) bool

func (*Client) UseCFTCompatibility

func (c *Client) UseCFTCompatibility() bool

func (*Client) UseCRC

func (c *Client) UseCRC() bool

UseCRC returns true if CRC is enabled for the client, and false otherwise.

func (*Client) UseNSDU

func (c *Client) UseNSDU() bool

func (*Client) UsePreConnection

func (c *Client) UsePreConnection() bool

type ClientTransfer

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

ClientTransfer is a struct representing the client side of a PeSIT transfer.

func NewTransfer

func NewTransfer(method Method, filename string) *ClientTransfer

NewTransfer initializes a new client transfer with the given method and filename.

func (*ClientTransfer) AccessControl

func (t *ClientTransfer) AccessControl() string

AccessControl returns the Password and new password of the Customer according to PI 63. (Not used).

func (*ClientTransfer) ArticleFormat

func (t *ClientTransfer) ArticleFormat() ArticleFormat

ArticleFormat returns the format of the transferred articles (if used) according to PI 31.

func (*ClientTransfer) ArticleSize

func (t *ClientTransfer) ArticleSize() uint16

ArticleSize returns the size of the transferred articles (if used) according to PI 32.

func (*ClientTransfer) BankID

func (t *ClientTransfer) BankID() string

BankID returs the ID of the bank according to PI 62.

func (*ClientTransfer) CheckpointSize

func (t *ClientTransfer) CheckpointSize() uint16

CheckpointSize returns the size of data transmitted between two checkpoints requests negotiated for the connection.

func (*ClientTransfer) CheckpointWindow

func (t *ClientTransfer) CheckpointWindow() uint8

CheckpointWindow returns the number of unackowledged checkpoint authorized before the emiter ceases to send data.

func (*ClientTransfer) ClientLogin

func (t *ClientTransfer) ClientLogin() string
  • TRANSFER PARAMETERS Get/Set

ClientLogin returns the client ID for the transfer.

func (*ClientTransfer) CloseFile

func (ct *ClientTransfer) CloseFile(src error) error

CloseFile requests the server to close the transferred file.

If Client.OpenFile has not been called, CloseFile returns ErrInvalidOperation.

If StartDataTransfer has been call and has returned successfully, EndDataTransfer, Stop, Cancel or Error must be called before calling this function.

If any error occurring during the communication with the partner an error of type Diagnostic will be returned.

func (*ClientTransfer) Compression

func (t *ClientTransfer) Compression() Compression

Compression returns the PeSIT compression used for the transfer according to PI 21.

func (*ClientTransfer) CreationDate

func (t *ClientTransfer) CreationDate() time.Time

CreationDate returns the date of the file creation according to PI 51.

func (*ClientTransfer) CustomerID

func (t *ClientTransfer) CustomerID() string

CustomerID returs the ID of the customer according to PI 61.

func (*ClientTransfer) DataCoding

func (t *ClientTransfer) DataCoding() DataCoding

DataCoding returns the data coding of the transfer according to PI 16.

func (*ClientTransfer) DeselectFile

func (ct *ClientTransfer) DeselectFile(src error) error

DeselectFile requests the server to deselect the transferred file.

If Client.SelectFile has not been called, DeselectFile returns ErrInvalidOperation.

If OpenFile has been call and has returned successfully, CloseFile must be called before calling this function.

If any error occurring during the communication with the partner an error of type Diagnostic will be returned.

Once this function returns no other actions can be called on the transfer.

func (*ClientTransfer) EndDataTransfer

func (ct *ClientTransfer) EndDataTransfer() error

EndDataTransfer successfully terminates the transfer.

If the transferred size is to be exchanged, SetTransferredBytes or SetTransferredArticlesit must be called before calling this function.

If StartDataTransfer has not been called, EndDataTransfer returns ErrInvalidOperation.

Once this function has been called no further call to Read/Write is allowed until StartDataTransfer is called once more.

func (*ClientTransfer) FileLabelPI37

func (t *ClientTransfer) FileLabelPI37() string

FileLabel returs the label of the transferred file according to PI 37. This may contain the filename of the requested file.

func (*ClientTransfer) FileOrganization

func (t *ClientTransfer) FileOrganization() FileOrganization

FileOrganization returns the organization of the transferred file according to PI 33.

func (*ClientTransfer) FileType

func (t *ClientTransfer) FileType() uint16

FileType returns the file type of the transfer according PI 11.

func (*ClientTransfer) Filename

func (ct *ClientTransfer) Filename() string

Filename returns the target file of the transfer. If the client is in CFT Compatibility mode and the transfer is in send mode the function will return the content of the PI37 FileLabel. Otherwise it will return the content of the PI12 Filename.

func (*ClientTransfer) FilenamePI12

func (t *ClientTransfer) FilenamePI12() string

FilenamePI12 returns the filename of the target file according to PI 12.

func (*ClientTransfer) FreeText

func (t *ClientTransfer) FreeText() string

FreeText returns the content of PI 99.

func (*ClientTransfer) GetNextRecvArticle

func (t *ClientTransfer) GetNextRecvArticle() (io.Reader, error)

StartNextRecvArticle returns a reader from which the next article can be read. If no more article are to be received GetNextRecvArticle returns an ErrNoMoreArticle.

func (*ClientTransfer) HasTransferEnded

func (t *ClientTransfer) HasTransferEnded() bool

func (*ClientTransfer) HasTransferStarted

func (t *ClientTransfer) HasTransferStarted() bool

HasTransferStarted returns false if the actual data transfer has not been started or if it has ended. It returns true otherwise.

func (*ClientTransfer) IsFileOpened

func (t *ClientTransfer) IsFileOpened() bool

IsFileSelected returns false if the target file of the transfer has not been opened yet or if it has been closed. It returns true otherwise.

func (*ClientTransfer) IsFileSelected

func (t *ClientTransfer) IsFileSelected() bool

IsFileSelected returns false if the target file of the transfer has not been selected yet or if it has been deselected. It returns true otherwise.

func (*ClientTransfer) IsReceive

func (t *ClientTransfer) IsReceive() bool

IsReceive indicates whether the transfer is in receive mode, i.e. if a client or a server sends a file to a partner.

If IsReceive returns true, the Read method can be used safely.

func (*ClientTransfer) IsRecovered

func (t *ClientTransfer) IsRecovered() bool

IsRecovered returns true is the transferred is a recovered one according to PI 15 and false otherwise.

func (*ClientTransfer) IsSend

func (t *ClientTransfer) IsSend() bool

IsSend indicates whether the transfer is in send mode, i.e. if a client or a server sends a file to a partner.

If IsSend returns true, the Write method can be used safely.

func (*ClientTransfer) IsTransferring

func (t *ClientTransfer) IsTransferring() bool

func (*ClientTransfer) Key

func (t *ClientTransfer) Key() (uint16, uint16)

Key returns the indexation key length and offset of the transferred file if the file is indexed (FileOrganization() == OrgIndexed) according to PI 38 and PI 39.

func (*ClientTransfer) KeyLength

func (t *ClientTransfer) KeyLength() uint16

KeyLength returns the indexation key length of the transferred file if the file is indexed (FileOrganization() == OrgIndexed) according to PI 38.

func (*ClientTransfer) KeyOffset

func (t *ClientTransfer) KeyOffset() uint16

KeyOffset returns the indexation key offset of the transferred file if the file is indexed (FileOrganization() == OrgIndexed) according to PI 39.

func (*ClientTransfer) LastAccess

func (t *ClientTransfer) LastAccess() time.Time

LastAccess returns the date of the file last access according to PI 52.

func (*ClientTransfer) ManualArticleHandling

func (t *ClientTransfer) ManualArticleHandling() bool

func (*ClientTransfer) MessageSize

func (t *ClientTransfer) MessageSize() uint16

MessageSize returns the maximum size of the exchanged PeSIT packets according to PI 25.

func (*ClientTransfer) OpenFile

func (ct *ClientTransfer) OpenFile() error

OpenFile requests the server to open the transferred file of the transfer.

If a compression algorithm is desired for the transfer it must be set before calling this function. Once this function returns GetCompression can be called to check the result of the negotiation.

If Client.SelectFile has not been called, OpenFile returns ErrInvalidOperation.

If any error occurring during the communication with the partner an error of type Diagnostic will be returned.

func (*ClientTransfer) Priority

func (t *ClientTransfer) Priority() Priority

Priority returns the priority of the transfer according to PI 17.

func (*ClientTransfer) RecoveryPoint

func (t *ClientTransfer) RecoveryPoint() uint32

RecoveryPoint returns the checkpoint at which the transfer should be restarted according to PI 18.

func (*ClientTransfer) RequestedAttributes

func (t *ClientTransfer) RequestedAttributes() Attributes

RequestedAttributes returns the file attributes requested according to PI 14.

func (*ClientTransfer) ReservationSpace

func (t *ClientTransfer) ReservationSpace() (uint32, FileSizeUnit)

ReservationSpace returns the file size and unit of the transferred file according to PI 41 and PI 42.

func (*ClientTransfer) ReservationSpaceMaxSize

func (t *ClientTransfer) ReservationSpaceMaxSize() uint32

ReservationSpace returns the file size unit of the transferred file according to PI 42.

func (*ClientTransfer) ReservationSpaceUnit

func (t *ClientTransfer) ReservationSpaceUnit() FileSizeUnit

ReservationSpace returns the file size of the transferred file according to PI 41.

func (*ClientTransfer) Restart

func (t *ClientTransfer) Restart(checkpoint uint32, srcErr error) (uint32, error)

Restart can be used to restart the transfer at an earlier point, i.e from the beginning of the file or from checkpoint after the last ackowledge one.

The checkpoint is the restart point asked to the partner. It must be higher or equal to the last ackowledge checkpoint. The partner can accept it or ask for another restart point. The return value indicates the result of the negotiation.

An error can be provided. It is sent to the server. If it is nil, a generic one is provided to the server.

Restart can only be used if the restart capability is enabled between the client and the server.

func (*ClientTransfer) ServerLogin

func (t *ClientTransfer) ServerLogin() string

ServerLogin returns the ID chosen by the server for the transfer.

func (*ClientTransfer) SetAccessControl

func (ct *ClientTransfer) SetAccessControl(access string) bool

SetAccessControl sets the content of PI63 File Access Control. This is used to provide a secret in order to access the transferred file. This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SetArticleFormat

func (ct *ClientTransfer) SetArticleFormat(f ArticleFormat) bool

SetArticleFormat sets the content of the PI31 Article Format. This function must be call before calling Client.OpenFile. You cannot set the Article Format of a transfer in receive mode.

func (*ClientTransfer) SetArticleSize

func (ct *ClientTransfer) SetArticleSize(s uint16) bool

SetArticleSize sets the content of the PI32 Article Size. This function must be call before calling Client.OpenFile. You cannot set the Article Size of a transfer in receive mode.

func (*ClientTransfer) SetBankID

func (ct *ClientTransfer) SetBankID(id string) bool

SetBankID sets the content of PI62 Bank ID. This can be used to forward server identifier to the end point server in Store and Forward Mode (cf: Annexe B). This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SetCompression

func (ct *ClientTransfer) SetCompression(compression Compression) bool

SetCompression sets the content of PI21 Compression. This sets the compression algorithm for the transfer of the file. This function must be call before calling Client.OpenFile or inside the ClientTransfer.FileSelected callback.

func (*ClientTransfer) SetCreationDate

func (ct *ClientTransfer) SetCreationDate(t time.Time) bool

SetCreationDate sets the content of PI51 Creation Date. This parameter provides the date of the creation of the file. This function must be call before calling Client.OpenFile. You cannot set the Creation Date of a transfer in receive mode.

func (*ClientTransfer) SetCustomerID

func (ct *ClientTransfer) SetCustomerID(id string) bool

SetCustomerID sets the content of PI61 Customer ID. This can be used to forward client identifier to the end point server in Store and Forward Mode (cf: Annexe B). This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SetDataCoding

func (ct *ClientTransfer) SetDataCoding(d DataCoding) bool

SetDataCoding sets the content of the PI16 Data Coding. This parameter informs the server about the type of content of the transferred file. You cannot set the Data Coding of a transfer in receive mode. This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SetFileLabelPI37

func (ct *ClientTransfer) SetFileLabelPI37(label string) bool

SetFileLabelPI37 sets the content of PI37 File Label. This parameter is use to transfer additional information about the transferred file. WARNING: Some PeSIT solutions use PI37 FileLabel to communicate the target file. This function must be call before calling Client.OpenFile. You cannot set the File Label of a transfer in receive mode.

func (*ClientTransfer) SetFileOrganization

func (ct *ClientTransfer) SetFileOrganization(o FileOrganization) bool

SetFileOrganization sets the content of the PI33 File Organizaton. This function must be call before calling Client.OpenFile. You cannot set the File Organization of a transfer in receive mode.

func (*ClientTransfer) SetFileType

func (ct *ClientTransfer) SetFileType(val uint16) bool

SetFileType sets the PI11 FileType of the transfer. This parameter is used to indicate that specific actions are to be taken. This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SetFilename

func (ct *ClientTransfer) SetFilename(filename string) bool

SetFilename sets the target file of the transfer. If the client is in CFT Compatibility mode and the transfer is in send mode the function will set the content of the PI37 FileLabel. Otherwise it will set the content of the PI12 Filename. This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SetFilenamePI12

func (ct *ClientTransfer) SetFilenamePI12(val string) bool

SetFilenamePI12 sets the content of the PI12 Filename. This parameter is used to indicate the target file of the transfer. WARNING: Some PeSIT solutions use PI37 FileLabel to communicate the target file. Use SetFileLabel37 function or the SetFilename function in CFTCompatibilty Mode to set the target file for those protocol. This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SetFreeText

func (ct *ClientTransfer) SetFreeText(text string) bool

SetFreeText sets the content of PI99 Free Text. This is used to provide additional information regarding the transfer. This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SetKey

func (ct *ClientTransfer) SetKey(length, offset uint16) bool

SetKey sets the content of PI38 Key Length and PI39 Key Offset. Those parameters sets the access information for a transferred indexed file (See PI33 File Organization). This function must be call before calling Client.OpenFile. You cannot set the Key Length and Offset of a transfer in receive mode.

func (*ClientTransfer) SetLastAccess

func (ct *ClientTransfer) SetLastAccess(t time.Time) bool

SetLastAccess sets the content of PI52 Last Access. This parameter provides the date of the last transfer (failed or successful) of the file. This function must be call before calling Client.OpenFile. You cannot set the Last Access of a transfer in receive mode.

func (*ClientTransfer) SetManualArticleHandling

func (ct *ClientTransfer) SetManualArticleHandling(manual bool) bool

SetManualArticleHandling enable/disable the automatic opening/closure of new articles for the transfer. This option is only valid for transfer using ArticleFormat FormatVariable. This function must be call before calling ClientTransfer.Read or ClientTransfer.Write.

func (*ClientTransfer) SetMessageSize

func (ct *ClientTransfer) SetMessageSize(s uint16) bool

SetMessageSize sets the content of the PI25 Message Size. This parameter sets the maximum size (in byte) of the exchanged PeSIT packets. This function must be call before calling Client.OpenFile. If the provided size is less than 800 bytes the parameter will be set to 800.

func (*ClientTransfer) SetPriority

func (ct *ClientTransfer) SetPriority(p Priority) bool

SetPriority sets the content of the PI17 Transfer Priority. This parameter informs the server about the urgency of the transfer. This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SetRecovered

func (ct *ClientTransfer) SetRecovered(recovered bool) bool

SetRecovered sets the content of the PI15 Recovered Transfer. This parameter marks the transfer as the recovery of a previous transfer. The TransferID must be set to the TransferID of the previous transfer. This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SetRecoveryPoint

func (ct *ClientTransfer) SetRecoveryPoint(point uint32) bool

SetRecoveryPoint sets the content of PI18 Recovery Point. This sets the starting point of the data for a recovered transfer. This function must be call before calling ClientTransfer.Read or ClientTransfer.Write.

func (*ClientTransfer) SetRequestedAttributes

func (ct *ClientTransfer) SetRequestedAttributes(a Attributes) bool

SetRequestedAttributes sets the content of the PI14 Requested Attribtues. This function must be call before calling Client.OpenFile. You cannot set the Requested Attributes of a transfer in send mode.

func (*ClientTransfer) SetReservationSpace

func (ct *ClientTransfer) SetReservationSpace(size uint32, unit FileSizeUnit) bool

SetReservationSpace sets the content of PI41 Space Reservation Unit and PI 42 Space Reservation Max Size. Those parameters define an upper bound for the size of the transferred file. This function must be call before calling Client.OpenFile. You cannot set the Reservation Space of a transfer in receive mode.

func (*ClientTransfer) SetSignatureUsage

func (ct *ClientTransfer) SetSignatureUsage(u bool) bool

SetSignatureUsage sets the content of PI34 Signature Usage. This informs the server that the file is transferred with is SIT Sceal. This function must be call before calling Client.OpenFile. You cannot set the Signature Usage of a transfer in receive mode. This parameter is ignored in NonSIT profile.

func (*ClientTransfer) SetSitMAC

func (ct *ClientTransfer) SetSitMAC(s uint64) bool

SetSitMAC sets the content of PI36 Sit MAC. This parameter contains the SIT Sceal of the transferred file. This function must be call before calling Client.OpenFile. You cannot set the Sit MAC of a transfer in receive mode. This parameter is ignored in NonSIT profile.

func (*ClientTransfer) SetTransferID

func (ct *ClientTransfer) SetTransferID(val uint32) bool

SetTransferID sets the content of the PI13 TransferID. This parameter is used to identify the transfer between the client and the server. Only the 24 significant bits are used You cannot set the TransferID of a transfer in receive mode unless the transfer is in recovery mode. This function must be call before calling Client.OpenFile.

func (*ClientTransfer) SignatureUsage

func (t *ClientTransfer) SignatureUsage() bool

SignatureUsage returns true if the transferred file is scealed by SIT according to PI 34. (Not Used).

func (*ClientTransfer) SitMAC

func (t *ClientTransfer) SitMAC() uint64

SitMAC returns the SIT sceal if the transferred file is scealed by SIT according to PI 35. (Not Used).

func (*ClientTransfer) StartDataTransfer

func (ct *ClientTransfer) StartDataTransfer() error

StartDataTransfer informs the server that the transfer of the file can begin.

If a recovery point is wanted for the transfer, SetRecoveryPoint must be called before calling this function. Once this function returns GetRecoveryPoint can be called to check the result of the negotiation.

If OpenFile has not been called, StartDataTransfer returns ErrInvalidOperation.

If any error occurring during the communication with the partner an error of type Diagnostic will be returned.

func (*ClientTransfer) StartNextSendArticle

func (t *ClientTransfer) StartNextSendArticle() (io.Writer, error)

StartNextSendArticle returns a writer into which the next article can be written. If the article segmentation is set to be automatic, StartNextSendArticle returns an ErrInvalidWriteMode.

func (*ClientTransfer) Stop

func (t *ClientTransfer) Stop(cause StopCause, srcErr error) error

Stop informs the transfer partner that the transfer has been suspended for the provided cause and error. The transfer can be recovered if the cause is not StopCancel.

If the transfer is done by a client, and StartDataTransfer has not been called, Stop returns ErrInvalidOperation.

If any error occurs during the communication with the partner an error of type Diagnostic will be returned.

Once this function has been called no further call to Read/Write is allowed until StartDataTransfer is called once more.

func (*ClientTransfer) TransferID

func (t *ClientTransfer) TransferID() uint32

TransferID returns the ID of the transfer according to PI 13.

func (*ClientTransfer) UseClientLogin

func (t *ClientTransfer) UseClientLogin(use bool) bool

UseClientLogin forces the use of the client login during the selection process. Returns false if the selection process has already been done.

func (*ClientTransfer) UseServerLogin

func (t *ClientTransfer) UseServerLogin(use bool) bool

UseServerLogin forces the use of the server login during the selection process. Returns false if the selection process has already been done.

func (*ClientTransfer) Write

func (t *ClientTransfer) Write(buf []byte) (int, error)

Write write the provided buffer to the connection. The Article segmentation is handled automaticalty. If the article segmentation is set to be manual, Write returns an ErrInvalidWriteMode.

func (*ClientTransfer) WriteArticle

func (t *ClientTransfer) WriteArticle(buf []byte) (int, error)

type Compression

type Compression uint8

Compression specifies the compresison algorithm to be used for the transfer. The only valid algorithms are defined as constants (cf: Annexe A).

const (
	NoCompression Compression = 1 << iota
	Horizontal
	Vertical
	HorizontalVertical
)

type Connection

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

Connection represents a PeSIT connection established between the client and the server. It stores the parameters of the session.

Some parameters can be changed during the negotiation phase of the session opening, but cannot be changed after.

func (*Connection) Abort

func (c *Connection) Abort(srcErr error)

type ConnectionHandler

type ConnectionHandler interface {
	// Connect is called when the client request the
	// opening of the connection.
	// The `ServerConnection` object contains all the information about the
	// connection transmitted by the client, including those that are negotiated.
	// Some parameters can be changed directly on the connection, in which case
	// those parameters are sent back to the client in the response.
	//
	// If the returned error is nil, the connection is accepted. In that case, the
	// returned TransferHandler is used for every transfer Request from that
	// client.
	Connect(servConn *ServerConnection) (TransferHandler, error)

	// Release is called when the client request the
	// closing of the connection.
	Release(servConn *ServerConnection)
}

ConnectionHandler defines the interface o a struct which is able ot process a PeSIT connection.

type DataCoding

type DataCoding uint8

DataCoding represents how the data transferred is coded.

const (
	CodingBinary DataCoding = iota
	CodingASCII
	CodingEBCDIC
)

func (DataCoding) String

func (i DataCoding) String() string

type Diagnostic

type Diagnostic interface {
	error
	IsSuccess() bool
	GetCode() DiagnosticCode
	GetMessage() string
}

func NewDiagnostic

func NewDiagnostic(code diagnostics.DiagnosticCode, complements string) Diagnostic

type DiagnosticCode

type DiagnosticCode = diagnostics.DiagnosticCode

type FileOrganization

type FileOrganization uint8

FileOrganization describes how the data are organized within a file.

const (
	OrgSequential FileOrganization = iota
	OrgRelative
	OrgIndexed
)

func (FileOrganization) String

func (i FileOrganization) String() string

type FileSizeUnit

type FileSizeUnit uint8

FileSizeUnit defines in which unit the filesize is given: it can be kilobytes or articles.

const (
	UnitKB FileSizeUnit = iota
	UnitArticle
)

func (FileSizeUnit) String

func (i FileSizeUnit) String() string

type Method

type Method uint8

Method represents the method of a transfer. It can be Send or Receive.

const (

	// MethodSend is the method for a send transfer, i.e. where the dara are
	// sent by the partner (the transfer can be wtitten to).
	MethodSend Method

	// MethodRecv is the method for a receive transfer, i.e. where the dara are
	// received by the partner (the transfer can be read from).
	MethodRecv
)

func (Method) IsValid

func (m Method) IsValid() bool

IsValid verifies that a method is valid. The only valid methods are those defined as constants.

func (Method) String

func (i Method) String() string

type Priority

type Priority uint8

Priority represents the priority of a file transfer.

const (
	PriorityNormal Priority = iota
	PriorityLow
	PriorityUrgent
)

type Profile

type Profile string
const (
	SIT          Profile = "SIT"
	NonSIT       Profile = "NonSIT"
	SecureNonSIT Profile = "SecureNonSIT"
	ETEBAC       Profile = "ETEBAC"
)

type ProtocolVersion

type ProtocolVersion uint8

ProtocolVersion is the version of a protocol. The only valid versions are defined as constants.

*Only Version E is supported in this implementation*.

const (
	VersionUnknown ProtocolVersion = 0
	VersionD       ProtocolVersion = 1
	VersionE       ProtocolVersion = 2
)

type Server

type Server struct {
	// ValidatePreConnection is a callback called on every connection during
	// the pre connection step.
	// This can be used to perform a first authentication of the client.
	// If a non nil is return the pre connection step will terminates in error and
	// the connection will be closed.
	ValidatePreConnection func(login, password string) error

	// Ge
	GetProfile   func() Profile // FIXME present for future proofing
	Logger       *log.Logger
	NetworkTrace *log.Logger
	// contains filtered or unexported fields
}

Server is a PeSIT server. It can listen on a port and accept connections from PeSIT clients.

func NewServer

func NewServer(c ConnectionHandler) *Server

NewServer initializes a new server.

The connectionHandler will be called for every new incoming connection in separate goroutine.

func (*Server) Close

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

Close stops the server. If the given context has a timeout, it will wait for existing connections to end. When the timeout expires, or if the context has no timeout, the connections are terminated immediately.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(address string, tlsConfig *tls.Config) error

ListenAndServe opens a listener on the provided address and runs the PeSIT server over it. The server uses a TLS listener if the tlsConfig provided is not nil. This method returns when the server is closed or in case of error on the listener.

func (*Server) Serve

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

Serve runs the PeSIT server over the provided listener. This method returns when the server is closed or in case of error on the listener.

func (*Server) SetNSDUUsage deprecated

func (s *Server) SetNSDUUsage(use bool)

Deprecated: NSDU handling is now automated, this method do nothing.

SetNSDUUsage sets if the server uses NSDU. If the server uses a pre connecton step, the call of this method function is optional as the NSDU usage is set automatically at this step.

func (*Server) SetPreConnectionUsage deprecated

func (s *Server) SetPreConnectionUsage(use bool)

Deprecated: Preconnection handling is now automated, this method do nothing.

SetPreConnectionUsage sets if the server uses a pre connet steps.

func (*Server) UseNSDU deprecated

func (s *Server) UseNSDU() bool

Deprecated: NSDU handling is now automated, this method do nothing.

NSDU. If the server uses a pre connection step the use of NSDU is dynamicly set during this step.

func (*Server) UsePreConnection deprecated

func (s *Server) UsePreConnection() bool

Deprecated: Preconnection handling is now automated, this method do nothing.

UsePreConnection returns true if the server expects a pre connection step. This step can be used to "negotiate" the use of a NSDU and to perform a first authentication of the client.

func (*Server) WithPreConnectMaxSize deprecated

func (s *Server) WithPreConnectMaxSize(size uint16)

Deprecated: Preconnection handling is now automated, this method do nothing.

SetPreConnectionUsage sets if the server uses a pre connet steps. This as no effet is UsePreConnection is false.

type ServerConnection

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

func (*ServerConnection) Abort

func (sc *ServerConnection) Abort(cause error)

func (*ServerConnection) AccessType

func (sc *ServerConnection) AccessType() AccessType

AccessType indicates which access type the connection supports.

func (*ServerConnection) AllowCheckpoints

func (sc *ServerConnection) AllowCheckpoints(size uint16, window uint8) bool

AllowCheckpoints enables and sets up he checkpointing feature for the connection. It can only be changed during the negotiation phase. It has no effect after the negotiation.

For a server, if the client requested checkpoints, the server can disable them, or lower the parameters. If the client did not requested them, the server cannot enable them.

The argument size represents the size of transmitted data between two checkpoints. The window argument is the allowed number of sequential non-acknowledged checkpoints. Beyond that window, data transfer is scopped.

To disable checkpointing, set size to CheckpointDisabled.

The return value indicates if the value has been changed or not.

func (*ServerConnection) AllowRestart

func (sc *ServerConnection) AllowRestart(newRestart bool) bool

AllowRestart enables the restart service for the connection. It can only be changed during the negotiation phase. It has no effect after the negotiation.

Enabling restart also enables checkpoints, as the checkpoint service is a prerequisite of the restart service. If checkpoints were disabled, they are enabled with a size of 65535 and a window of 1. However, disabling restart *does not* disable checkpoints.

For a server, if the client requested restart, the server can disable it. If the client did not requested it, the server cannot enable it.

The return value indicates if the value has been changed or not.

func (*ServerConnection) CheckpointSize

func (sc *ServerConnection) CheckpointSize() uint16

CheckpointSize returns the saze of data transmitted between two checkpoints.

func (*ServerConnection) CheckpointWindow

func (sc *ServerConnection) CheckpointWindow() uint8

CheckpointWindow returns the allowed number of sequential non-acknowledged checkpoints.

func (*ServerConnection) ClientLogin

func (sc *ServerConnection) ClientLogin() string

func (*ServerConnection) ClientPassword

func (sc *ServerConnection) ClientPassword() string

func (*ServerConnection) FreeText

func (sc *ServerConnection) FreeText() string

func (*ServerConnection) HasCheckpoints

func (sc *ServerConnection) HasCheckpoints() bool

HasCheckpoints returns true if checkpoints are enabled for the client, and false otherwise.

func (*ServerConnection) HasRestart

func (sc *ServerConnection) HasRestart() bool

HasRestart returns true if restarts are enabled for the client, and false otherwise.

func (*ServerConnection) NewClientPassword

func (sc *ServerConnection) NewClientPassword() string

func (*ServerConnection) NewServerPassword

func (sc *ServerConnection) NewServerPassword() string

func (*ServerConnection) ServerLogin

func (sc *ServerConnection) ServerLogin() string

func (*ServerConnection) ServerPassword

func (sc *ServerConnection) ServerPassword() string

func (*ServerConnection) SetAccessType

func (sc *ServerConnection) SetAccessType(newAccessType AccessType) bool

SetAccessType changes the access type for the connection. It can only be changed during the negotiation phase. It has no effect after the negotiation.

For a server, the type of access requested by the client can only be downgraded. It means that the server can only limit the access type to read or write when the client requested read/write. It cannot be changed otherwise.

The return value indicates if the value has been changed or not.

func (*ServerConnection) SetCFTCompatibilityUsage

func (sc *ServerConnection) SetCFTCompatibilityUsage(usage bool) bool

func (*ServerConnection) SetCRCUsage

func (sc *ServerConnection) SetCRCUsage(newCRCUsage bool) bool

func (*ServerConnection) SetFreeText

func (sc *ServerConnection) SetFreeText(f string) bool

func (*ServerConnection) SetNewServerPassword

func (sc *ServerConnection) SetNewServerPassword(val string) bool

func (*ServerConnection) SetServerPassword

func (sc *ServerConnection) SetServerPassword(val string) bool

SetServerPassword sets the password of the server during the negotiation phase. This password, if set, is sent to the client in the server response to the connection.

This method has no effect if it is called after the negotiation phase.

The server password is limited to 8 7-bit ASCII characters. If the password is longer, it is truncated to 8 characters.

func (*ServerConnection) UseCFTCompatibility

func (sc *ServerConnection) UseCFTCompatibility() bool

func (*ServerConnection) UseCRC

func (sc *ServerConnection) UseCRC() bool

func (*ServerConnection) Version

func (sc *ServerConnection) Version() ProtocolVersion

type ServerTransfer

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

func (*ServerTransfer) AccessControl

func (t *ServerTransfer) AccessControl() string

AccessControl returns the Password and new password of the Customer according to PI 63. (Not used).

func (*ServerTransfer) ArticleFormat

func (t *ServerTransfer) ArticleFormat() ArticleFormat

ArticleFormat returns the format of the transferred articles (if used) according to PI 31.

func (*ServerTransfer) ArticleSize

func (t *ServerTransfer) ArticleSize() uint16

ArticleSize returns the size of the transferred articles (if used) according to PI 32.

func (*ServerTransfer) BankID

func (t *ServerTransfer) BankID() string

BankID returs the ID of the bank according to PI 62.

func (*ServerTransfer) CheckpointSize

func (t *ServerTransfer) CheckpointSize() uint16

CheckpointSize returns the size of data transmitted between two checkpoints requests negotiated for the connection.

func (*ServerTransfer) CheckpointWindow

func (t *ServerTransfer) CheckpointWindow() uint8

CheckpointWindow returns the number of unackowledged checkpoint authorized before the emiter ceases to send data.

func (*ServerTransfer) ClientLogin

func (t *ServerTransfer) ClientLogin() string
  • TRANSFER PARAMETERS Get/Set

ClientLogin returns the client ID for the transfer.

func (*ServerTransfer) Compression

func (t *ServerTransfer) Compression() Compression

Compression returns the PeSIT compression used for the transfer according to PI 21.

func (*ServerTransfer) CreationDate

func (t *ServerTransfer) CreationDate() time.Time

CreationDate returns the date of the file creation according to PI 51.

func (*ServerTransfer) CustomerID

func (t *ServerTransfer) CustomerID() string

CustomerID returs the ID of the customer according to PI 61.

func (*ServerTransfer) DataCoding

func (t *ServerTransfer) DataCoding() DataCoding

DataCoding returns the data coding of the transfer according to PI 16.

func (*ServerTransfer) FileLabelPI37

func (t *ServerTransfer) FileLabelPI37() string

FileLabel returs the label of the transferred file according to PI 37. This may contain the filename of the requested file.

func (*ServerTransfer) FileOrganization

func (t *ServerTransfer) FileOrganization() FileOrganization

FileOrganization returns the organization of the transferred file according to PI 33.

func (*ServerTransfer) FileType

func (t *ServerTransfer) FileType() uint16

FileType returns the file type of the transfer according PI 11.

func (*ServerTransfer) Filename

func (st *ServerTransfer) Filename() string

func (*ServerTransfer) FilenamePI12

func (t *ServerTransfer) FilenamePI12() string

FilenamePI12 returns the filename of the target file according to PI 12.

func (*ServerTransfer) FreeText

func (t *ServerTransfer) FreeText() string

FreeText returns the content of PI 99.

func (*ServerTransfer) GetNextRecvArticle

func (t *ServerTransfer) GetNextRecvArticle() (io.Reader, error)

StartNextRecvArticle returns a reader from which the next article can be read. If no more article are to be received GetNextRecvArticle returns an ErrNoMoreArticle.

func (*ServerTransfer) HasTransferEnded

func (t *ServerTransfer) HasTransferEnded() bool

func (*ServerTransfer) HasTransferStarted

func (t *ServerTransfer) HasTransferStarted() bool

HasTransferStarted returns false if the actual data transfer has not been started or if it has ended. It returns true otherwise.

func (*ServerTransfer) IsFileOpened

func (t *ServerTransfer) IsFileOpened() bool

IsFileSelected returns false if the target file of the transfer has not been opened yet or if it has been closed. It returns true otherwise.

func (*ServerTransfer) IsFileSelected

func (t *ServerTransfer) IsFileSelected() bool

IsFileSelected returns false if the target file of the transfer has not been selected yet or if it has been deselected. It returns true otherwise.

func (*ServerTransfer) IsReceive

func (t *ServerTransfer) IsReceive() bool

IsReceive indicates whether the transfer is in receive mode, i.e. if a client or a server sends a file to a partner.

If IsReceive returns true, the Read method can be used safely.

func (*ServerTransfer) IsRecovered

func (t *ServerTransfer) IsRecovered() bool

IsRecovered returns true is the transferred is a recovered one according to PI 15 and false otherwise.

func (*ServerTransfer) IsSend

func (t *ServerTransfer) IsSend() bool

IsSend indicates whether the transfer is in send mode, i.e. if a client or a server sends a file to a partner.

If IsSend returns true, the Write method can be used safely.

func (*ServerTransfer) IsTransferring

func (t *ServerTransfer) IsTransferring() bool

func (*ServerTransfer) Key

func (t *ServerTransfer) Key() (uint16, uint16)

Key returns the indexation key length and offset of the transferred file if the file is indexed (FileOrganization() == OrgIndexed) according to PI 38 and PI 39.

func (*ServerTransfer) KeyLength

func (t *ServerTransfer) KeyLength() uint16

KeyLength returns the indexation key length of the transferred file if the file is indexed (FileOrganization() == OrgIndexed) according to PI 38.

func (*ServerTransfer) KeyOffset

func (t *ServerTransfer) KeyOffset() uint16

KeyOffset returns the indexation key offset of the transferred file if the file is indexed (FileOrganization() == OrgIndexed) according to PI 39.

func (*ServerTransfer) LastAccess

func (t *ServerTransfer) LastAccess() time.Time

LastAccess returns the date of the file last access according to PI 52.

func (*ServerTransfer) ManualArticleHandling

func (t *ServerTransfer) ManualArticleHandling() bool

func (*ServerTransfer) MessageSize

func (t *ServerTransfer) MessageSize() uint16

MessageSize returns the maximum size of the exchanged PeSIT packets according to PI 25.

func (*ServerTransfer) Priority

func (t *ServerTransfer) Priority() Priority

Priority returns the priority of the transfer according to PI 17.

func (*ServerTransfer) RecoveryPoint

func (t *ServerTransfer) RecoveryPoint() uint32

RecoveryPoint returns the checkpoint at which the transfer should be restarted according to PI 18.

func (*ServerTransfer) RequestedAttributes

func (t *ServerTransfer) RequestedAttributes() Attributes

RequestedAttributes returns the file attributes requested according to PI 14.

func (*ServerTransfer) ReservationSpace

func (t *ServerTransfer) ReservationSpace() (uint32, FileSizeUnit)

ReservationSpace returns the file size and unit of the transferred file according to PI 41 and PI 42.

func (*ServerTransfer) ReservationSpaceMaxSize

func (t *ServerTransfer) ReservationSpaceMaxSize() uint32

ReservationSpace returns the file size unit of the transferred file according to PI 42.

func (*ServerTransfer) ReservationSpaceUnit

func (t *ServerTransfer) ReservationSpaceUnit() FileSizeUnit

ReservationSpace returns the file size of the transferred file according to PI 41.

func (*ServerTransfer) Restart

func (t *ServerTransfer) Restart(checkpoint uint32, srcErr error) (uint32, error)

Restart can be used to restart the transfer at an earlier point, i.e from the beginning of the file or from checkpoint after the last ackowledge one.

The checkpoint is the restart point asked to the partner. It must be higher or equal to the last ackowledge checkpoint. The partner can accept it or ask for another restart point. The return value indicates the result of the negotiation.

An error can be provided. It is sent to the server. If it is nil, a generic one is provided to the server.

Restart can only be used if the restart capability is enabled between the client and the server.

func (*ServerTransfer) ServerLogin

func (t *ServerTransfer) ServerLogin() string

ServerLogin returns the ID chosen by the server for the transfer.

func (*ServerTransfer) SetArticleFormat

func (st *ServerTransfer) SetArticleFormat(format ArticleFormat) bool

func (*ServerTransfer) SetArticleSize

func (st *ServerTransfer) SetArticleSize(size uint16) bool

func (*ServerTransfer) SetCompression

func (st *ServerTransfer) SetCompression(compression Compression) bool

func (*ServerTransfer) SetCreationDate

func (st *ServerTransfer) SetCreationDate(t time.Time) bool

func (*ServerTransfer) SetDataCoding

func (st *ServerTransfer) SetDataCoding(coding DataCoding) bool

func (*ServerTransfer) SetFileLabelPI37

func (st *ServerTransfer) SetFileLabelPI37(label string) bool

func (*ServerTransfer) SetFileOrganization

func (st *ServerTransfer) SetFileOrganization(orga FileOrganization) bool

func (*ServerTransfer) SetFileType

func (st *ServerTransfer) SetFileType(fileType uint16) bool

func (*ServerTransfer) SetFilename

func (st *ServerTransfer) SetFilename(filename string) bool

func (*ServerTransfer) SetFilenamePI12

func (st *ServerTransfer) SetFilenamePI12(filename string) bool

func (*ServerTransfer) SetFreeText

func (st *ServerTransfer) SetFreeText(text string) bool

func (*ServerTransfer) SetKey

func (st *ServerTransfer) SetKey(length, offset uint16) bool

func (*ServerTransfer) SetLastAccess

func (st *ServerTransfer) SetLastAccess(t time.Time) bool

func (*ServerTransfer) SetManualArticleHandling

func (st *ServerTransfer) SetManualArticleHandling(manual bool) bool

SetManualArticleHandling enable/disable the automatic opening/closure of new articles for the transfer. This option is only valid for transfer using ArticleFormat FormatVariable.

func (*ServerTransfer) SetMessageSize

func (st *ServerTransfer) SetMessageSize(size uint16) bool

func (*ServerTransfer) SetRecoveryPoint

func (st *ServerTransfer) SetRecoveryPoint(point uint32) bool

func (*ServerTransfer) SetReservationSpace

func (st *ServerTransfer) SetReservationSpace(size uint32, unit FileSizeUnit) bool

func (*ServerTransfer) SetSignatureUsage

func (st *ServerTransfer) SetSignatureUsage(sigUse bool) bool

func (*ServerTransfer) SetSitMAC

func (st *ServerTransfer) SetSitMAC(sitMAC uint64) bool

func (*ServerTransfer) SetTransferID

func (st *ServerTransfer) SetTransferID(id uint32) bool

func (*ServerTransfer) SignatureUsage

func (t *ServerTransfer) SignatureUsage() bool

SignatureUsage returns true if the transferred file is scealed by SIT according to PI 34. (Not Used).

func (*ServerTransfer) SitMAC

func (t *ServerTransfer) SitMAC() uint64

SitMAC returns the SIT sceal if the transferred file is scealed by SIT according to PI 35. (Not Used).

func (*ServerTransfer) StartNextSendArticle

func (t *ServerTransfer) StartNextSendArticle() (io.Writer, error)

StartNextSendArticle returns a writer into which the next article can be written. If the article segmentation is set to be automatic, StartNextSendArticle returns an ErrInvalidWriteMode.

func (*ServerTransfer) Stop

func (t *ServerTransfer) Stop(cause StopCause, srcErr error) error

Stop informs the transfer partner that the transfer has been suspended for the provided cause and error. The transfer can be recovered if the cause is not StopCancel.

If the transfer is done by a client, and StartDataTransfer has not been called, Stop returns ErrInvalidOperation.

If any error occurs during the communication with the partner an error of type Diagnostic will be returned.

Once this function has been called no further call to Read/Write is allowed until StartDataTransfer is called once more.

func (*ServerTransfer) TransferID

func (t *ServerTransfer) TransferID() uint32

TransferID returns the ID of the transfer according to PI 13.

func (*ServerTransfer) UseClientLogin

func (t *ServerTransfer) UseClientLogin(use bool) bool

UseClientLogin forces the use of the client login during the selection process. Returns false if the selection process has already been done.

func (*ServerTransfer) UseServerLogin

func (t *ServerTransfer) UseServerLogin(use bool) bool

UseServerLogin forces the use of the server login during the selection process. Returns false if the selection process has already been done.

func (*ServerTransfer) Write

func (t *ServerTransfer) Write(buf []byte) (int, error)

Write write the provided buffer to the connection. The Article segmentation is handled automaticalty. If the article segmentation is set to be manual, Write returns an ErrInvalidWriteMode.

func (*ServerTransfer) WriteArticle

func (t *ServerTransfer) WriteArticle(buf []byte) (int, error)

type StopCause

type StopCause uint8

StopCause specifies a cancel call and indicates its reason. The only valid causes are defined as constants.

const (
	// StopError indicates that there has been an error, and that the transfer will
	// restart after.
	StopError StopCause = iota

	// StopSuspend indicates a suspension in data transfer, that can resume
	// later, or in another connection.
	StopSuspend

	// StopCancel indicates that the server canceled.
	StopCancel
)

func (StopCause) String

func (i StopCause) String() string

type TransferHandler

type TransferHandler interface {
	// SelectFile is called when the client requests a file transfer. i
	// The `ServerTransfer` argument contains the parameters asked by the client
	// for the transfer.
	//
	// This Method must check that the transfer can be done :
	// - The file exist in case of a send transfer
	// - There is enough available space to store a file in receive mode
	// - The server has eanough resources to process it
	// - etc.
	//
	// Some parameters can be changed on the ServerTransfer struct. Those values
	// will be sent to the client in the response to the request.
	//
	// If the returned value is nil, the transfer request is accepted. If it is
	// an error, the transfer request is be refused: the error is sent to the
	// client as a reason. If the error is a Diagnostic, it is sent as is; if
	// not, it will be converted to a generic one with the error as message.
	SelectFile(servTrans *ServerTransfer) error

	// DeselectFile is called when the client end the transfer.
	// The error argument contains the error given by the client or nil if no
	// error has been encountered.
	//
	// This Method must finalize all remaining operations regarding the transfer.
	//
	// The deselect method is answered with the returned error or with success
	// if the error is nil.
	DeselectFile(err error) error

	// Openfile is called when the client asks the server to open the file to
	// store the data received or to read the data to send.
	//
	// Only the Compression and the RecoveryPoint parameters can be changed here.
	//
	// If any error occurs during the file openning, it can be returned. If the
	// error is a Diagnostic, it is sent as is; if not, it will be converted to
	// a generic one with the error as message.
	OpenFile(servTrans *ServerTransfer) error

	// CloseFile is called when the client requests the server to close the
	// file after data transfer.
	//
	// This method must close the file and return any resulting error. If the
	// error is a Diagnostic, it is sent as is; if not, it will be converted to
	// a generic one with the error as message.
	CloseFile(err error) error

	// StartDataTransfer is called when the client requests to start the
	// transfer of data.
	//
	// If the transfer is recovered, the recoverypoint is communicated in this
	// stage.
	//
	// If the transfer is in send mode (the client asks to receive data), the
	// recovery point asked by the client is set on DataTransferRequest. If the
	// server cannot recover the transfer to the asked checkpoint, it must
	// return an diagnostic error with the code `CodeRestartNegotiationFailure`.
	//
	// If the transfer is in receive mode (the client asks to send data), the
	// recovery point can be set by the server on ServerTransfer.
	StartDataTransfer(servTrans *ServerTransfer) error

	// EndTransfer is called when the client asks to end the file transfer.
	//
	// Any operation can be done to this effect in this method.
	//
	// If the error is a Diagnostic, it is sent as is; if not, it will be
	// converted to a generic one with the error as message. When an error
	// occurs, CloseFile and Finalize are called when the client requests it.
	EndTransfer(servTrans *ServerTransfer, err error) error

	// DataTransfer is called after the client has requested the transfer of
	// data, i.e. when the data can be transferred.
	//
	// This method must handle the read or write of the data from or to the
	// transfer.
	//
	// Every method of the transfer and every callback can be defined at this
	// stage.
	//
	// If any error occurs during data transfer, it can be returned. If the
	// error is a Diagnostic, it is sent as is; if not, it will be converted to
	// a generic one with the error as message.
	//
	// If ServerTransfer.Stop will be called if it has not been called before
	// returning an non nil error (this is not advised)
	DataTransfer(servTrans *ServerTransfer) error
}

TransferHandler defines the interface of a struct which is able to process a transfer from start to finish.

It is used by the server when a client requests a file transfer in an established connection.

Each method of the interface corresponds to a step of the transfer.

Source Files

  • client.go
  • client_transfer.go
  • codec.go
  • connection.go
  • doc.go
  • enums.go
  • errors.go
  • nsdu_handler.go
  • pipeline.go
  • server.go
  • server_connection.go
  • server_transfer.go
  • string_access_type.go
  • string_article_format.go
  • string_connection_state.go
  • string_data_coding.go
  • string_file_organization.go
  • string_file_size_unit.go
  • string_method.go
  • string_stop_cause.go
  • transfer.go
  • utils.go

Directories

Path Synopsis
examples
client command
server command
internal
diagnostics
Package diagnostics creates constants for the diagnostic codes defined in the protocol specifications.
Package diagnostics creates constants for the diagnostic codes defined in the protocol specifications.
encoding
Package encoding provides utilities to marshal and unmarshal some values to and from a binary stream suitable for the pesit protocol.
Package encoding provides utilities to marshal and unmarshal some values to and from a binary stream suitable for the pesit protocol.
fpdus
Package fpdus provide the definitions of the network packets of the PeSIT protocol.
Package fpdus provide the definitions of the network packets of the PeSIT protocol.
params
Package params defines the parameter used in FPDUs.
Package params defines the parameter used in FPDUs.
primitives
Package primitives provide the definitions of the functional units of the PeSIT protocol.
Package primitives provide the definitions of the functional units of the PeSIT protocol.
profiles
Package profiles defines the PeSIT profiles used.
Package profiles defines the PeSIT profiles used.

Jump to

Keyboard shortcuts

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