func doInit(out io.Writer, repoRoot string, force bool, nBitsForKeypair int) error { if _, err := fmt.Fprintf(out, "initializing ipfs node at %s\n", repoRoot); err != nil { return err } if err := checkWriteable(repoRoot); err != nil { return err } if fsrepo.IsInitialized(repoRoot) && !force { return errRepoExists } conf, err := config.Init(out, nBitsForKeypair) if err != nil { return err } if fsrepo.IsInitialized(repoRoot) { if err := fsrepo.Remove(repoRoot); err != nil { return err } } if err := fsrepo.Init(repoRoot, conf); err != nil { return err } if err := addDefaultAssets(out, repoRoot); err != nil { return err } return initializeIpnsKeyspace(repoRoot) }
func doInit(out io.Writer, repoRoot string, empty bool, nBitsForKeypair int, conf *config.Config) error { if _, err := fmt.Fprintf(out, "initializing ipfs node at %s\n", repoRoot); err != nil { return err } if err := checkWriteable(repoRoot); err != nil { return err } if fsrepo.IsInitialized(repoRoot) { return errRepoExists } if conf == nil { var err error conf, err = config.Init(out, nBitsForKeypair) if err != nil { return err } } if err := fsrepo.Init(repoRoot, conf); err != nil { return err } if !empty { if err := addDefaultAssets(out, repoRoot); err != nil { return err } } return initializeIpnsKeyspace(repoRoot) }
func doInit(out io.Writer, repoRoot string, force bool, empty bool, nBitsForKeypair int) error { log.Println("initializing ipfs node at ", repoRoot) if err := checkWriteable(repoRoot); err != nil { return err } if fsrepo.IsInitialized(repoRoot) && !force { log.Println("repo already exists") return nil } conf, err := config.Init(out, nBitsForKeypair) if err != nil { return err } if fsrepo.IsInitialized(repoRoot) { if err := fsrepo.Remove(repoRoot); err != nil { return err } } if err := fsrepo.Init(repoRoot, conf); err != nil { return err } if !empty { if err := addDefaultAssets(out, repoRoot); err != nil { return err } } return initializeIpnsKeyspace(repoRoot) }
func startupIPFS(dspath string, ctx *context.Context) (*core.IpfsNode, error) { r, err := fsrepo.Open(dspath) if err != nil { config, err := config.Init(os.Stdout, 2048) if err != nil { return nil, err } if err := fsrepo.Init(dspath, config); err != nil { return nil, err } r, err = fsrepo.Open(dspath) if err != nil { return nil, err } } //fmt.Println(r) node, err := core.NewNode(*ctx, &core.BuildCfg{Online: true, Repo: r}) if err != nil { return nil, err } return node, nil }
func NewTmpDirNode(ctx context.Context) (*core.IpfsNode, error) { dir, err := ioutil.TempDir("", "ipfs-shell") if err != nil { return nil, fmt.Errorf("failed to get temp dir: %s", err) } cfg, err := config.Init(ioutil.Discard, 1024) if err != nil { return nil, err } err = fsrepo.Init(dir, cfg) if err != nil { return nil, fmt.Errorf("failed to init ephemeral node: %s", err) } repo, err := fsrepo.Open(dir) if err != nil { return nil, err } return core.NewNode(ctx, &core.BuildCfg{ Online: true, Repo: repo, }) }
func ensureRepoInitialized(path string) error { if !fsrepo.IsInitialized(path) { conf, err := config.Init(ioutil.Discard, *nBitsForKeypair) if err != nil { return err } if err := fsrepo.Init(path, conf); err != nil { return err } } return nil }
func DoInit(out io.Writer, repoRoot string, nBitsForKeypair int, testnet bool, password string, dbInit func(string, []byte, string) error) error { if err := maybeCreateOBDirectories(repoRoot); err != nil { return err } if fsrepo.IsInitialized(repoRoot) { return ErrRepoExists } if err := checkWriteable(repoRoot); err != nil { return err } conf, err := initConfig(out) if err != nil { return err } mnemonic, err := createMnemonic() if err != nil { return err } seed := bip39.NewSeed(mnemonic, "Secret Passphrase") fmt.Printf("generating %d-bit RSA keypair...", nBitsForKeypair) identityKey, err := ipfs.IdentityKeyFromSeed(seed, nBitsForKeypair) if err != nil { return err } fmt.Printf("done\n") identity, err := ipfs.IdentityFromKey(identityKey) if err != nil { return err } log.Infof("initializing openbazaar node at %s\n", repoRoot) if err := fsrepo.Init(repoRoot, conf); err != nil { return err } conf.Identity = identity if err := addConfigExtensions(repoRoot, testnet); err != nil { return err } if err := dbInit(mnemonic, identityKey, password); err != nil { return err } return initializeIpnsKeyspace(repoRoot, identityKey) }
// CreateIpfsRepo initializes an empty .ipfs directory at `ipfsRootPath`. // ipfsRootPath should contain the ".ipfs" at the end. func CreateIpfsRepo(ipfsRootPath string) error { logger := &logutil.Writer{Level: log.InfoLevel} cfg, err := ipfsconfig.Init(logger, 2048) if err != nil { return err } if err := fsrepo.Init(ipfsRootPath, cfg); err != nil { return err } return nil }
// InitRepo creates an initialized .ipfs directory in the directory `path`. // The generated RSA key will have `keySize` bits. func InitRepo(path string, keySize int) (string, error) { if err := os.MkdirAll(path, 0744); err != nil { return "", err } cfg, err := ipfsconfig.Init(ioutil.Discard, keySize) if err != nil { return "", err } if err := fsrepo.Init(path, cfg); err != nil { return "", err } return path, nil }