net-protocol

module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: Apache-2.0

README

net-protocol

GitHub last commit GitHub GitHub code size in bytes

基于go 实现链路层、网络层、传输层、应用层 网络协议栈 ,使用虚拟网卡实现

@docs

相关md文档在cmd目录下,以及相关协议的demo测试

./cmd/*.md

一、相关协议进度

@application 应用层
@transport 传输层
@network 网络层
  • icmp
  • ipv4
  • ipv6
@物理层
  • tun tap 虚拟网卡的实现

二、协议相关api

1.应用层相关协议

应用层暂时只实现了http、websocket、等文本协议。都基于tcp实现,对tcp等进行二次封装

http:

//新建一个初始化server,(底层 会创建一个tap网卡并注册 路由,arp缓存等),初始化端口机制,添加9502到端口表
serv := http.NewHTTP("tap1", "192.168.1.0/24", "192.168.1.1", "9502")
//添加路由,当对应请求到来时,分发到自定义回调函数中处理
serv.HandleFunc("/", func(request *http.Request, response *http.Response) 
//赋值给将要发送响应给客户端的 buf
Response.End("string");
//启动监听网卡、启动tcp、启动dispatch 分发事件并阻塞 等待client连接。。
serv.ListenAndServ()

websocket:初始化阶段和httpserver一致、新建httpserver、设置路由、启动监听服务

// r *http.Request, w *http.Response
// Upgrade 为校验websocket协议, 并将http协议升级为websocket协议。并接管http协议流程,直接进行tcp通讯保持连接,
c, err := websocket.Upgrade(r, w)

	//循环处理数据,接受数据,然后返回
	for {
    //读取客户端数据,该方法一直阻塞直到收到客户端数据,会触发通道取消阻塞
		message, err := c.ReadData()
    //发送数据给客户端,封装包头包体,调用tcpWrite 封装tcp包头,写入网络层 封装ip包头、写入链路层 封装以太网包头、写入网卡
		c.SendData([]byte("hello"))
	}
2.传输层相关协议

tcp

udp

port端口机制

Directories

Path Synopsis
cmd
pkg
buffer
Package buffer provides the implementation of a buffer view.
Package buffer provides the implementation of a buffer view.
ilist
Package ilist provides the implementation of intrusive linked lists.
Package ilist provides the implementation of intrusive linked lists.
rand
Package rand implements a cryptographically secure pseudorandom number generator.
Package rand implements a cryptographically secure pseudorandom number generator.
seqnum
Package seqnum defines the types and methods for TCP sequence numbers such that they fit in 32-bit words and work properly when overflows occur.
Package seqnum defines the types and methods for TCP sequence numbers such that they fit in 32-bit words and work properly when overflows occur.
sleep
Package sleep allows goroutines to efficiently sleep on multiple sources of notifications (wakers).
Package sleep allows goroutines to efficiently sleep on multiple sources of notifications (wakers).
tmutex
Package tmutex provides the implementation of a mutex that implements an efficient TryLock function in addition to Lock and Unlock.
Package tmutex provides the implementation of a mutex that implements an efficient TryLock function in addition to Lock and Unlock.
waiter
Package waiter provides the implementation of a wait queue, where waiters can be enqueued to be notified when an event of interest happens.
Package waiter provides the implementation of a wait queue, where waiters can be enqueued to be notified when an event of interest happens.
Package tcpip provides the interfaces and related types that users of the tcpip stack will use in order to create endpoints used to send and receive data over the network stack.
Package tcpip provides the interfaces and related types that users of the tcpip stack will use in order to create endpoints used to send and receive data over the network stack.
header
Package header provides the implementation of the encoding and decoding of network protocol headers.
Package header provides the implementation of the encoding and decoding of network protocol headers.
link/loopback
Package loopback provides the implemention of loopback data-link layer endpoints.
Package loopback provides the implemention of loopback data-link layer endpoints.
network/arp
Package arp implements the ARP network protocol.
Package arp implements the ARP network protocol.
network/fragmentation
Package fragmentation contains the implementation of IP fragmentation.
Package fragmentation contains the implementation of IP fragmentation.
network/hash
Package hash contains utility functions for hashing.
Package hash contains utility functions for hashing.
network/ipv4
Package ipv4 contains the implementation of the ipv4 network protocol.
Package ipv4 contains the implementation of the ipv4 network protocol.
network/ipv6
Package ipv6 contains the implementation of the ipv6 network protocol.
Package ipv6 contains the implementation of the ipv6 network protocol.
ports
Package ports provides PortManager that manages allocating, reserving and releasing ports.
Package ports provides PortManager that manages allocating, reserving and releasing ports.
transport/ping
Package ping contains the implementation of the ICMP and IPv6-ICMP transport protocols for use in ping.
Package ping contains the implementation of the ICMP and IPv6-ICMP transport protocols for use in ping.
transport/tcp
Package tcp contains the implementation of the TCP transport protocol.
Package tcp contains the implementation of the TCP transport protocol.
transport/tcp/testing/context
Package context provides a test context for use in tcp tests.
Package context provides a test context for use in tcp tests.
transport/tcpconntrack
Package tcpconntrack implements a TCP connection tracking object.
Package tcpconntrack implements a TCP connection tracking object.
transport/udp
Package udp contains the implementation of the UDP transport protocol.
Package udp contains the implementation of the UDP transport protocol.
Package stack provides the glue between networking protocols and the consumers of the networking stack.
Package stack provides the glue between networking protocols and the consumers of the networking stack.

Jump to

Keyboard shortcuts

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