【问题标题】:Can't build TCP connection with peers to send handshake message in golang, Bittorrent client无法与对等方建立 TCP 连接以在 golang、Bittorrent 客户端中发送握手消息
【发布时间】:2023-01-30 00:16:37
【问题描述】:

我正在尝试构建一个 bittorrent 客户端。我编写此函数是为了验证我是否可以建立连接以向其他对等方发送消息,但它不起作用。

func handShake(torrent *gotorrentparser.Torrent, peer Peer, peedId []byte) {

    conn,err := net.Dial("tcp", peer.ip + ":" + strconv.Itoa(int(peer.port)))

    if err != nil {
        panic(err)
    }
    defer conn.Close()
}

这里的 peer 是字符串 ip 和 uint16 端口的结构。

出现以下错误: panic: dial tcp 152.57.73.47:27569: connectex: A connection attempt failed because the connected party didn't properly respond after a period time, or established connection failed because connected host has failed respond.

找不到任何类似的问题。我试图将我的本地端口地址修复为与我用来发送公告请求的地址相同,但这也没有用。

编辑:我尝试使用不同的种子,它对一些同行失败了,但现在它正在为其他一些同行工作。只有当对等方将 utorrent 用作 bittorrent 客户端时才会出现问题吗?

【问题讨论】:

  • 你弄错了 IP,弄错了端口,没有从“这里到那里”和/或“那里到这里”的网络路由,或者服务器没有运行。
  • 如果我从追踪器那里收到它怎么会错呢?
  • 在这一点上,我建议使用 wireshark 来找出网络中真正发生的事情。
  • 连接被防火墙阻止或使用 127.0.0.1 或 IP 的任何本地地址。因为代码没有错。
  • “我从追踪器那里收到的,怎么会错呢?”追踪器经常出错

标签: go tcp p2p bittorrent


【解决方案1】:

如果您正在开发一个 bittorrent 客户端,您应该从一个更可重现的设置开始,例如在您的本地机器上运行一个具有已知 infohash 的现有客户端,然后连接到它(不使用跟踪器)。一旦你让它工作,你就可以在跟踪器客户端实现上工作,然后将这些部分放在一起。

互联网不可靠并且 bittorrent 由许多移动部分组成,因此单个连接失败不会告诉你太多,你必须确保每个部分都正常工作并尝试使用你在现有客户端中测试过的 torrent 来缩小范围问题的原因。

【讨论】:

    猜你喜欢
    • 2012-11-27
    • 2014-04-27
    • 2019-09-20
    • 2021-01-23
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多