ipfs / kubo

An IPFS implementation in Go
https://docs.ipfs.tech/how-to/command-line-quick-start/
Other
16.16k stars 3.01k forks source link

Cannot retrieve content by addressing with SHA256 (raw binary?) #10426

Closed ghost closed 5 months ago

ghost commented 5 months ago

Checklist

Installation method

built from source

Version

Kubo version: 0.29.0-dev
Repo version: 15
System version: amd64/linux
Golang version: go1.22.2

Config

{
  "API": {
    "HTTPHeaders": {}
  },
  "Addresses": {
    "API": "/ip4/127.0.0.1/tcp/5001",
    "Announce": [],
    "AppendAnnounce": [],
    "Gateway": "/ip4/127.0.0.1/tcp/8080",
    "NoAnnounce": [],
    "Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip6/::/tcp/4001",
      "/ip4/0.0.0.0/udp/4001/quic-v1",
      "/ip4/0.0.0.0/udp/4001/quic-v1/webtransport",
      "/ip6/::/udp/4001/quic-v1",
      "/ip6/::/udp/4001/quic-v1/webtransport"
    ]
  },
  "AutoNAT": {},
  "Bootstrap": [
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
    "/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
    "/ip4/104.131.131.82/udp/4001/quic-v1/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
  ],
  "DNS": {
    "Resolvers": {}
  },
  "Datastore": {
    "BloomFilterSize": 0,
    "GCPeriod": "1h",
    "HashOnRead": false,
    "Spec": {
      "mounts": [
        {
          "child": {
            "path": "blocks",
            "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
            "sync": true,
            "type": "flatfs"
          },
          "mountpoint": "/blocks",
          "prefix": "flatfs.datastore",
          "type": "measure"
        },
        {
          "child": {
            "compression": "none",
            "path": "datastore",
            "type": "levelds"
          },
          "mountpoint": "/",
          "prefix": "leveldb.datastore",
          "type": "measure"
        }
      ],
      "type": "mount"
    },
    "StorageGCWatermark": 90,
    "StorageMax": "10GB"
  },
  "Discovery": {
    "MDNS": {
      "Enabled": true
    }
  },
  "Experimental": {
    "FilestoreEnabled": false,
    "GraphsyncEnabled": false,
    "Libp2pStreamMounting": false,
    "OptimisticProvide": false,
    "OptimisticProvideJobsPoolSize": 0,
    "P2pHttpProxy": false,
    "StrategicProviding": false,
    "UrlstoreEnabled": false
  },
  "Gateway": {
    "APICommands": [],
    "DeserializedResponses": null,
    "DisableHTMLErrors": null,
    "ExposeRoutingAPI": null,
    "HTTPHeaders": {},
    "NoDNSLink": false,
    "NoFetch": false,
    "PathPrefixes": [],
    "PublicGateways": null,
    "RootRedirect": ""
  },
  "Identity": {
    "PeerID": "12D3KooWQpMv9ZuXEaBHQEmBUKc1FZdXzbQGwqFmtV5AJuSGSs2y"
  },
  "Internal": {},
  "Ipns": {
    "RecordLifetime": "",
    "RepublishPeriod": "",
    "ResolveCacheSize": 128
  },
  "Migration": {
    "DownloadSources": [],
    "Keep": ""
  },
  "Mounts": {
    "FuseAllowOther": false,
    "IPFS": "/ipfs",
    "IPNS": "/ipns"
  },
  "Peering": {
    "Peers": null
  },
  "Pinning": {
    "RemoteServices": {}
  },
  "Plugins": {
    "Plugins": null
  },
  "Provider": {
    "Strategy": ""
  },
  "Pubsub": {
    "DisableSigning": false,
    "Router": ""
  },
  "Reprovider": {},
  "Routing": {
    "AcceleratedDHTClient": false,
    "Methods": null,
    "Routers": null
  },
  "Swarm": {
    "AddrFilters": null,
    "ConnMgr": {},
    "DisableBandwidthMetrics": false,
    "DisableNatPortMap": false,
    "RelayClient": {},
    "RelayService": {},
    "ResourceMgr": {},
    "Transports": {
      "Multiplexers": {},
      "Network": {},
      "Security": {}
    }
  }
}

Description

After a file is added to kubo with ipfs add, it cannot be retrieved from the API using the added file's hash.

For example

# Create test file
dd if=/dev/zero of=3MB bs=3M count=1

ipfs add 3MB
# added QmekBGp284QtNZoJg812EYkv3w55dNGt5Jxwjbg6g2ZRin 3MB

# Request using returned CID
curl localhost:8080/ipfs/QmekBGp284QtNZoJg812EYkv3w55dNGt5Jxwjbg6g2ZRin
# <a href="http://bafybeihtyhuhusxdrdxfrghtodthjwzroluaqm7zafjyb2a2e4c6h3uba4.ipfs.localhost:8080/">Moved Permanently</a>.

curl http://bafybeihtyhuhusxdrdxfrghtodthjwzroluaqm7zafjyb2a2e4c6h3uba4.ipfs.localhost:8080/
# Warning: Binary output can mess up your terminal. Use "--output -" to tell 
# Warning: curl to output it to your terminal anyway, or consider "--output 
# Warning: <FILE>" to save to a file.

##################
# Request using SHA256
sha256sum 3M
# bbd05cf6097ac9b1f89ea29d2542c1b7b67ee46848393895f5a9e43fa1f621e5  3MB

curl localhost:8080/ipfs/f01551220bbd05cf6097ac9b1f89ea29d2542c1b7b67ee46848393895f5a9e43fa1f621e5
# <a href="http://bafkreif32bopmcl2zgy7rhvctusufqnxwz7oi2cihe4jl5nj4q72d5rb4u.ipfs.localhost:8080/">Moved Permanently</a>.

curl http://bafkreif32bopmcl2zgy7rhvctusufqnxwz7oi2cihe4jl5nj4q72d5rb4u.ipfs.localhost:8080/
# just hangs

The resulting base32 CIDs are also different

name type CID
original dag-pb bafybeihtyhuhusxdrdxfrghtodthjwzroluaqm7zafjyb2a2e4c6h3uba4
from SHA256 raw bafkreif32bopmcl2zgy7rhvctusufqnxwz7oi2cihe4jl5nj4q72d5rb4u

Edit: Doesn't work for raw binary with blake3 hashsum (f01551e200471c2e7ccc927709c1e41e299804f1c2d2c2b757ff5afd5a3172bd68b9bccc2)

Edit2: Specifically, it fails when trying to find the a block at this point https://github.com/ipfs/go-ds-flatfs/blob/3b1c91bc3097ec7702347d8a419269ce88e450b8/flatfs.go#L658 (found using breakpoints). Maybe there's something wrong with CID parsing? dunno....

lidel commented 5 months ago

I think the short answer is that you are using made-up CID to retrieve data, which has no providers, so it hangs while looking for them. If you use the one returned by ipfs add it will work.

TLDR:

I'm closing this (there is no bug in Kubo), but posting some resources for learning how IPFS handles files below.

The video course at:

And related docs:

For further support, try reaching out to https://discuss.ipfs.tech/c/help/13 (we limit github to bugs and feature requests), thanks!