torrent 'magnet:?xt=urn:btih:KRWPCX3SJUM4IMM4YF5RPHL6ANPYTQPU'
rhash --btih ubuntu-14.04.2-desktop-amd64.iso
3b94daf4aeaae3f4a930b4466cb8af81d44bb305 ubuntu-14.04.2-desktop-amd64.iso
package main
import (
"github.com/anacrolix/torrent/metainfo"
"fmt"
"path/filepath"
"github.com/anacrolix/torrent/bencode"
)
func main() {
filename:="ubuntu-14.04.2-desktop-amd64.iso"
d:=makeMagnet("/home/sjtu-lyj/dht/server_data",filename)
fmt.Println(d)
}
func makeMagnet( dir string, name string) string {
mi := metainfo.MetaInfo{}
mi.SetDefaults()
info := metainfo.Info{PieceLength: 1024*1024}
info.BuildFromFilePath(filepath.Join(dir, name))
mi.InfoBytes, _ = bencode.Marshal(info)
magnet := mi.Magnet(name, mi.HashInfoBytes()).String()
return magnet
}
// magnet:?xt=urn:btih:3b94daf4aeaae3f4a930b4466cb8af81d44bb305&dn=ubuntu-14.04.2-desktop-amd64.iso