This commit is contained in:
nic
2025-07-23 17:56:38 +03:00
parent a31b9310a2
commit 1c181d7e22
10 changed files with 196 additions and 44 deletions
+6 -5
View File
@@ -11,8 +11,9 @@ import (
)
const (
tcpNetwork = "tcp"
bufferSize = 32 * 1024 // 32KB
tcpNetwork = "tcp"
bufferSize = 32 * 1024 // 32KB
AHEAD_CHACHA20_POLY1305 = "AEAD_CHACHA20_POLY1305" // Default method cipher
)
// Ошибки подключения
@@ -34,7 +35,7 @@ func NewPeer(pubKey string) *Peer {
}
}
func (p *Peer) Connect(ip, port string) error {
func (p *Peer) Connect(endpoint string) error {
p.mu.Lock()
defer p.mu.Unlock()
@@ -42,12 +43,12 @@ func (p *Peer) Connect(ip, port string) error {
return nil // Уже подключен
}
conn, err := net.Dial(tcpNetwork, net.JoinHostPort(ip, port))
conn, err := net.Dial(tcpNetwork, endpoint)
if err != nil {
return err
}
cipher, err := core.PickCipher("AEAD_CHACHA20_POLY1305", []byte(p.pubKey), "")
cipher, err := core.PickCipher(AHEAD_CHACHA20_POLY1305, []byte(p.pubKey), "")
if err != nil {
conn.Close()
return err