github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/protocol/connection.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package protocol 4 5 type Connections interface { 6 GuestConnectionCount() uint64 7 8 GetConnectionByPeerAddr(addr [16]byte) (conn Connection, err Error) 9 // A connection can use just by single app node, so user can't use same connection to connect other node before close connection on usage node. 10 GetConnectionByUserIDDelegateUserID(userID, delegateUserID [16]byte) (conn Connection, err Error) 11 GetConnectionsByUserID(userID [16]byte) (conns []Connection, err Error) 12 GetConnectionByDomain(domain string) (conn Connection, err Error) 13 14 // state=unregistered -> 'register' -> state=registered -> 'deregister' -> state=unregistered. 15 RegisterConnection(conn Connection) (err Error) 16 DeregisterConnection(conn Connection) (err Error) 17 } 18 19 // Connection or App2AppConnection indicate how connection create and save in time series data. 20 // Each user pair with delegate-user has a chain that primary key is UserID+DelegateUserID 21 type Connection interface { 22 /* Connection data */ 23 MTU() int 24 Status() ConnectionState // return last connection state 25 State() chan ConnectionState // return state channel to listen to new connection state. for more than one listener use channel hub(repeater) 26 Weight() Weight 27 28 /* Peer data */ 29 Addr() [16]byte 30 AddrType() NetworkLinkNextHeaderID 31 DomainName() string // if exist 32 UserID() UserID 33 DelegateUserID() UserID // Persons can delegate to things(as a user type) 34 35 Close() (err Error) // Just once 36 Revoke() (err Error) // Just once 37 38 Streams 39 ConnectionMetrics 40 } 41 42 // ConnectionMetrics 43 type ConnectionMetrics interface { 44 LastUsage() TimeUnixMilli // Last use of the connection 45 MaxBandwidth() uint64 // Byte/Second and Connection can limit to a fixed number 46 BytesSent() uint64 // Counts the bytes of packets sent 47 PacketsSent() uint64 // Counts sent packets 48 BytesReceived() uint64 // Counts the bytes of packets receive 49 PacketsReceived() uint64 // Counts received packets 50 LostPackets() uint64 // 51 LostBytes() uint64 // 52 FailedPacketsReceived() uint64 // Counts failed packets receive for firewalling server from some attack types 53 NotRequestedPacketsReceived() uint64 // Counts not requested packets received for firewalling server from some attack types 54 SucceedStreamCount() uint64 // Count successful request 55 FailedStreamCount() uint64 // Count failed services call e.g. data validation failed, ... 56 57 StreamSucceed() 58 StreamFailed() 59 PacketReceived(packetLength uint64) 60 PacketSent(packetLength uint64) 61 PacketResend(packetLength uint64) 62 } 63 64 // ConnectionState indicate connection and stream state 65 type ConnectionState uint8 66 67 // Standrad Connection States 68 const ( 69 ConnectionState_Unset ConnectionState = iota // State not set yet 70 ConnectionState_New // means connection not saved yet to storage 71 ConnectionState_Loaded // means connection load from storage 72 ConnectionState_Unregistered 73 74 ConnectionState_Opening // connection||stream plan to open and not ready to accept stream 75 ConnectionState_Open // connection||stream is open and ready to use 76 ConnectionState_Closing // connection||stream plan to close and not accept new stream 77 ConnectionState_Closed // connection||stream had been closed 78 79 ConnectionState_NotResponse // peer not response to recently send request 80 ConnectionState_RateLimited // connection||stream limited due to higher usage than permitted 81 ConnectionState_Timeout // connection||stream timeout(DeadlineExceeded) and must close 82 83 ConnectionState_BrokenPacket 84 ConnectionState_NeedMoreData 85 ConnectionState_Sending 86 ConnectionState_Receiving 87 ConnectionState_ReceivedCompletely 88 ConnectionState_SentCompletely 89 90 ConnectionState_Encrypted 91 ConnectionState_Decrypted 92 ConnectionState_Ready 93 ConnectionState_Idle 94 95 ConnectionState_Blocked 96 ConnectionState_BlockedByPeer 97 98 // Each package can declare it's own state with ConnectionState > 127 e.g. tcp: TCP_SYN_SENT, TCP_SYN_RECV, ... 99 )