Пример #1
0
func (c *client) Add(r io.Reader) (Key, error) {
	// SliceFile is a workaround for https://github.com/jbenet/go-ipfs/issues/392
	// FIXME pass ReaderFile to NewRequest
	f := &cmds.SliceFile{"TODO",
		[]cmds.File{
			&cmds.ReaderFile{Filename: "TODO", Reader: r},
		},
	}
	req, err := cmds.NewRequest([]string{"add"}, nil, nil, f, core_cmds.AddCmd, nil)
	if err != nil {
		return nil, err
	}
	res, err := c.httpClient.Send(req)
	if err != nil {
		return nil, err
	}
	switch v := res.Output().(type) {
	case *core_cmds.AddOutput:
		if len(v.Objects) < 1 {
			return nil, errors.New("malformed response")
		}
		k, err := parseKey(v.Objects[0].Hash)
		if err != nil {
			return nil, err
		}
		return k, nil
	default:
		return nil, errors.New("unrecognized output format")
	}
}
Пример #2
0
func (ov OptionValue) String() (string, bool, error) {
	if !ov.found {
		return "", false, nil
	}
	val, ok := ov.value.(string)
	if !ok {
		return "", false, debugerror.New("cast")
	}
	return val, ov.found, nil
}
Пример #3
0
func stringListMarshaler(res cmds.Response) ([]byte, error) {
	list, ok := res.Output().(*stringList)
	if !ok {
		return nil, errors.New("failed to cast []string")
	}

	var buf bytes.Buffer
	for _, s := range list.Strings {
		buf.Write([]byte(s))
		buf.Write([]byte("\n"))
	}
	return buf.Bytes(), nil
}
Пример #4
0
func initIdentity(cfg *config.Identity, peers peer.Peerstore, online bool) (peer.Peer, error) {
	if cfg.PeerID == "" {
		return nil, debugerror.New("Identity was not set in config (was ipfs init run?)")
	}

	if len(cfg.PeerID) == 0 {
		return nil, debugerror.New("No peer ID in config! (was ipfs init run?)")
	}

	// get peer from peerstore (so it is constructed there)
	id := peer.ID(b58.Decode(cfg.PeerID))
	self, err := peers.Get(id)
	if err != nil {
		return nil, err
	}
	self.SetType(peer.Local)
	self, err = peers.Add(self)
	if err != nil {
		return nil, err
	}

	self.SetVersions(handshake.ClientVersion, handshake.IpfsVersion.String())

	// when not online, don't need to parse private keys (yet)
	if online {
		skb, err := base64.StdEncoding.DecodeString(cfg.PrivKey)
		if err != nil {
			return nil, err
		}

		if err := self.LoadAndVerifyKeyPair(skb); err != nil {
			return nil, err
		}
	}

	return self, nil
}
Пример #5
0
// Load reads given file and returns the read config, or error.
func Load(filename string) (*Config, error) {
	// if nothing is there, fail. User must run 'ipfs init'
	if !u.FileExists(filename) {
		return nil, debugerror.New("ipfs not initialized, please run 'ipfs init'")
	}

	var cfg Config
	err := ReadConfigFile(filename, &cfg)
	if err != nil {
		return nil, err
	}

	// tilde expansion on datastore path
	cfg.Datastore.Path, err = u.TildeExpansion(cfg.Datastore.Path)
	if err != nil {
		return nil, err
	}

	return &cfg, err
}
Пример #6
0
func (c *client) Open(filename string) (http.File, error) {
	return nil, errors.New("TODO")
}