sharpshooter

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2021 License: MIT Imports: 16 Imported by: 0

README

Sharpshooter

GitHub GitHub commit activity

Sharpshooter is a reliability network protocol using UDP.

It is a connection-oriented protocol just like TCP.

It doesn't have packet characteristics,You can try it to bypassing some protocol characteristics detection,and base for P2P application transport protocol.

About instructions , you can see example dir, I provided tow simple example.

If want TCP to sharpshooter convert , can try https://github.com/soyum2222/sharpshooter-tunel .

Specification

| SIZE(4byte) | SQE(4byte) | CMD(2byte) | CONTENT(.......) |

SIZE:
    contain SQE CMD CONTENT byte size . but not contain itself byte size .
    
SQE
    sequence number, continuous data package, SQE is continuous.
    
CMD
    0:ack
    1:NORMAL
    2:first handshack
    3:second handshack(response first handshack)
    4:third handshack
    5:close connction(FIN)
    6:response close
    7:health check
    8:response health 
       
ACK package
    
| SIZE(4byte) | SQE(4byte) | CMD(2byte) | ackSQE1(4byte)| ackSQE2(4byte) | ackSQE3(4byte) | ... |
    
The package max length can't over DEFAULT_INIT_PACKSIZE or Sniper.packageSize      

When receive ack like :

    | SIZE(4byte) | SQE(4byte) | CMD(2byte) | ackSQE1(4byte)| ackSQE2(4byte) | ackSQE3(4byte) |
    
if ackSQE1 == ackSQE2 and ackSQE1 < ackSQE3 this situation means ackSQE1 to ackSQE3 is continuous number .

eg:  receive data : |0|0|0|1|1|10| , this means other party sent ack 1 to 10.

Use

Ping pong

ping.go

pong.go

File transfer

send_file.go

receive_file.go

Network utilization

try transfer 100M file

speed

utilization

utilization depends on network status and send window size

Documentation

Index

Constants

View Source
const (
	DEFAULT_HEAD_SIZE                          = 20
	DEFAULT_INIT_SENDWIND                      = 64
	DEFAULT_INIT_RECEWIND                      = 1 << 10
	DEFAULT_INIT_PACKSIZE                      = 1000
	DEFAULT_INIT_HEALTHTICKER                  = 1
	DEFAULT_INIT_HEALTHCHECK_TIMEOUT_TRY_COUNT = 10
	DEFAULT_INIT_HANDSHACK_TIMEOUT             = 6
	DEFAULT_INIT_RTO_UNIT                      = float64(200 * time.Millisecond)
	DEFAULT_INIT_DELAY_ACK                     = float64(200 * time.Millisecond)
	DEFAULT_INIT_INTERVAL                      = 500
)
View Source
const (
	STATUS_NONE = iota
	STATUS_SECONDHANDSHACK
	STATUS_THIRDHANDSHACK
	STATUS_NORMAL
	STATUS_CLOSEING1
	STATUS_CLOSEING2
	STATUS_CLOSEING3
)

Variables

View Source
var (
	CLOSEERROR         = errors.New("the connection is closed")
	HEALTHTIMEOUTERROR = errors.New("health monitor timeout ")
	TIMEOUERROR        = timeout(0)
	RCVAMMOBAGEMPTY    = make([]*protocol.Ammo, DEFAULT_INIT_RECEWIND)
)

Functions

func Dial

func Dial(addr string) (net.Conn, error)

func Listen

func Listen(addr string) (*headquarters, error)

func NewHeadquarters

func NewHeadquarters() *headquarters

Types

type Sniper

type Sniper struct {
	Statistics
	// contains filtered or unexported fields
}

func NewSniper

func NewSniper(conn *net.UDPConn, aim *net.UDPAddr) *Sniper

func (*Sniper) CleanStatistics added in v0.1.6

func (s *Sniper) CleanStatistics()

func (*Sniper) Close

func (s *Sniper) Close() error

func (*Sniper) Debug added in v0.1.6

func (s *Sniper) Debug()

func (*Sniper) LocalAddr

func (s *Sniper) LocalAddr() net.Addr

func (*Sniper) OpenFec

func (s *Sniper) OpenFec(dataShards, parShards int)

OpenFec use FEC algorithm in communication this will waste some of traffic , but when the packet is lost there is a certain probability that the lost packet can be recovered

func (*Sniper) OpenStaTraffic added in v0.1.6

func (s *Sniper) OpenStaTraffic()

func (*Sniper) Read

func (s *Sniper) Read(b []byte) (n int, err error)

func (*Sniper) RemoteAddr

func (s *Sniper) RemoteAddr() net.Addr

func (*Sniper) SetDeadline

func (s *Sniper) SetDeadline(t time.Time) error

func (*Sniper) SetInterval

func (s *Sniper) SetInterval(interval int64)

func (*Sniper) SetPackageSize added in v0.1.6

func (s *Sniper) SetPackageSize(size int64)

func (*Sniper) SetReadDeadline

func (s *Sniper) SetReadDeadline(t time.Time) error

func (*Sniper) SetRecWin

func (s *Sniper) SetRecWin(size int64)

func (*Sniper) SetSendWin

func (s *Sniper) SetSendWin(size int32)

func (*Sniper) SetWriteDeadline

func (s *Sniper) SetWriteDeadline(t time.Time) error

func (*Sniper) TrafficStatistics added in v0.1.6

func (s *Sniper) TrafficStatistics() Statistics

func (*Sniper) Write

func (s *Sniper) Write(b []byte) (n int, err error)

type Statistics added in v0.1.6

type Statistics struct {
	TotalTraffic     int64
	EffectiveTraffic int64
	TotalPacket      int64
	EffectivePacket  int64
	RTT              int64
	RTO              int64
	SendWin          int64
	ReceiveWin       int64
}

type TimedSched added in v0.1.2

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

TimedSched represents the control struct for timed parallel scheduler

var SystemTimedSched *TimedSched = NewTimedSched(runtime.NumCPU())

SystemTimedSched is the library level timed-scheduler

func NewTimedSched added in v0.1.2

func NewTimedSched(parallel int) *TimedSched

NewTimedSched creates a parallel-scheduler with given parallelization

func (*TimedSched) Close added in v0.1.2

func (ts *TimedSched) Close()

Close terminates this scheduler

func (*TimedSched) Put added in v0.1.2

func (ts *TimedSched) Put(f func(), deadline time.Time)

Put a function 'f' awaiting to be executed at 'deadline'

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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