Skip to content

CarterTsai/tcp-shaker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TCP Shaker 💓

Go Report Card GoDoc

Performing TCP handshake without ACK, useful for health checking.

HAProxy does this exactly the same, which is:

  • SYN
  • SYN-ACK
  • RST

Why do I have to do this?

Usually when you establish a TCP connection(e.g. net.Dial), these are the first three packets (TCP three-way handshake):

  • Client -> Server: SYN
  • Server -> Client: SYN-ACK
  • Client -> Server: ACK

This package tries to avoid the last ACK when doing handshakes.

By sending the last ACK, the connection is considered established.

However as for TCP health checking the last ACK may not necessary.

The Server could be considered alive after it sends back SYN-ACK.

Benefits of avoiding the last ACK:

  1. Less packets better efficiency
  2. The health checking is less obvious

The second one is essential, because it bothers server less.

Usually this means the server will not notice the health checking traffic at all, thus the act of health checking will not be considered as some misbehaviour of client.

Requirements:

  • Linux 2.4 or newer

Usage

	import "github.com/tevino/tcp-shaker"

	s := tcp.Shaker{}
	if err := s.Init(); err != nil {
		log.Fatal("Shaker init failed:", err)
	}

	timeout := time.Second * 1
	err := s.Test("google.com:80", timeout)
	switch err {
	case tcp.ErrTimeout:
		fmt.Println("Connect to Google timeout")
	case nil:
		fmt.Println("Connect to Google succeded")
	default:
		if e, ok := err.(*tcp.ErrConnect); ok {
			fmt.Println("Connect to Google failed:", e)
		} else {
			fmt.Println("Error occurred while connecting:", err)
		}
	}

TODO:

  • IPv6 support (Test environment needed, PRs are welcomed)

About

💓 Performing TCP handshake without ACK in golang, useful for health checking, that is SYN, SYN-ACK, RST.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%