Example #1
0
	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
	cmds "github.com/djbarber/ipfs-hack/commands"
	cmdsCli "github.com/djbarber/ipfs-hack/commands/cli"
	cmdsHttp "github.com/djbarber/ipfs-hack/commands/http"
	core "github.com/djbarber/ipfs-hack/core"
	coreCmds "github.com/djbarber/ipfs-hack/core/commands"
	repo "github.com/djbarber/ipfs-hack/repo"
	config "github.com/djbarber/ipfs-hack/repo/config"
	fsrepo "github.com/djbarber/ipfs-hack/repo/fsrepo"
	u "github.com/djbarber/ipfs-hack/util"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

// log is the command logger
var log = logging.Logger("cmd/ipfs")

var (
	errUnexpectedApiOutput = errors.New("api returned unexpected output")
	errApiVersionMismatch  = errors.New("api version mismatch")
)

const (
	EnvEnableProfiling = "IPFS_PROF"
	cpuProfile         = "ipfs.cpuprof"
	heapProfile        = "ipfs.memprof"
	errorFormat        = "ERROR: %v\n\n"
)

type cmdInvocation struct {
	path []string
Example #2
0
	"net"
	"time"

	msgio "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-msgio"
	mpool "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-msgio/mpool"
	ma "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
	manet "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
	ic "github.com/djbarber/ipfs-hack/p2p/crypto"
	peer "github.com/djbarber/ipfs-hack/p2p/peer"
	u "github.com/djbarber/ipfs-hack/util"
	lgbl "github.com/djbarber/ipfs-hack/util/eventlog/loggables"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("conn")

// ReleaseBuffer puts the given byte array back into the buffer pool,
// first verifying that it is the correct size
func ReleaseBuffer(b []byte) {
	log.Debugf("Releasing buffer! (cap,size = %d, %d)", cap(b), len(b))
	mpool.ByteSlicePool.Put(uint32(cap(b)), b)
}

// singleConn represents a single connection to another Peer (IPFS Node).
type singleConn struct {
	local  peer.ID
	remote peer.ID
	maconn manet.Conn
	msgrw  msgio.ReadWriteCloser
	event  io.Closer
Example #3
0
	addrutil "github.com/djbarber/ipfs-hack/p2p/net/swarm/addr"
	peer "github.com/djbarber/ipfs-hack/p2p/peer"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"

	ma "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
	ps "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-peerstream"
	pst "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-stream-muxer"
	psy "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-stream-muxer/yamux"
	"github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/goprocess"
	goprocessctx "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
	prom "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus"
	mafilter "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/whyrusleeping/multiaddr-filter"
	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
)

var log = logging.Logger("swarm2")

var PSTransport pst.Transport

var peersTotal = prom.NewGaugeVec(prom.GaugeOpts{
	Namespace: "ipfs",
	Subsystem: "p2p",
	Name:      "peers_total",
	Help:      "Number of connected peers",
}, []string{"peer_id"})

func init() {
	tpt := *psy.DefaultTransport
	tpt.MaxStreamWindowSize = 512 * 1024
	PSTransport = &tpt
}
Example #4
0
package corehttp

import (
	"fmt"
	"net"
	"net/http"
	"time"

	ma "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
	manet "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
	"github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/goprocess"
	core "github.com/djbarber/ipfs-hack/core"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("core/server")

// ServeOption registers any HTTP handlers it provides on the given mux.
// It returns the mux to expose to future options, which may be a new mux if it
// is interested in mediating requests to future options, or the same mux
// initially passed in if not.
type ServeOption func(*core.IpfsNode, net.Listener, *http.ServeMux) (*http.ServeMux, error)

// makeHandler turns a list of ServeOptions into a http.Handler that implements
// all of the given options, in order.
func makeHandler(n *core.IpfsNode, l net.Listener, options ...ServeOption) (http.Handler, error) {
	topMux := http.NewServeMux()
	mux := topMux
	for _, option := range options {
		var err error
		mux, err = option(n, l, mux)
Example #5
0
import (
	"fmt"
	"os"

	"github.com/djbarber/ipfs-hack/commands/files"
	bal "github.com/djbarber/ipfs-hack/importer/balanced"
	"github.com/djbarber/ipfs-hack/importer/chunk"
	h "github.com/djbarber/ipfs-hack/importer/helpers"
	trickle "github.com/djbarber/ipfs-hack/importer/trickle"
	dag "github.com/djbarber/ipfs-hack/merkledag"
	"github.com/djbarber/ipfs-hack/pin"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("importer")

// Builds a DAG from the given file, writing created blocks to disk as they are
// created
func BuildDagFromFile(fpath string, ds dag.DAGService, mp pin.ManualPinner) (*dag.Node, error) {
	stat, err := os.Lstat(fpath)
	if err != nil {
		return nil, err
	}

	if stat.IsDir() {
		return nil, fmt.Errorf("`%s` is a directory", fpath)
	}

	f, err := files.NewSerialFile(fpath, fpath, stat)
	if err != nil {
Example #6
0
import (
	"bytes"
	"io"
	"testing"

	u "github.com/djbarber/ipfs-hack/util"
	testutil "github.com/djbarber/ipfs-hack/util/testutil"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"

	ic "github.com/djbarber/ipfs-hack/p2p/crypto"
	peer "github.com/djbarber/ipfs-hack/p2p/peer"

	ma "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
)

var log = logging.Logger("boguskey")

// TestBogusPrivateKey is a key used for testing (to avoid expensive keygen)
type TestBogusPrivateKey []byte

// TestBogusPublicKey is a key used for testing (to avoid expensive keygen)
type TestBogusPublicKey []byte

func (pk TestBogusPublicKey) Verify(data, sig []byte) (bool, error) {
	log.Errorf("TestBogusPublicKey.Verify -- this better be a test!")
	return bytes.Equal(data, reverse(sig)), nil
}

func (pk TestBogusPublicKey) Bytes() ([]byte, error) {
	return []byte(pk), nil
}
Example #7
0
package tour

import (
	"strconv"
	"strings"

	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("tour")

// ID is a string identifier for topics
type ID string

// LessThan returns whether this ID is sorted earlier than another.
func (i ID) LessThan(o ID) bool {
	return compareDottedInts(string(i), string(o))
}

// IDSlice implements the sort interface for ID slices.
type IDSlice []ID

func (a IDSlice) Len() int           { return len(a) }
func (a IDSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a IDSlice) Less(i, j int) bool { return a[i].LessThan(a[j]) }

// Topic is a type of objects that structures a tour topic.
type Topic struct {
	ID ID
	Content
}
Example #8
0
package mocknet

import (
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"

	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
)

var log = logging.Logger("mocknet")

// WithNPeers constructs a Mocknet with N peers.
func WithNPeers(ctx context.Context, n int) (Mocknet, error) {
	m := New(ctx)
	for i := 0; i < n; i++ {
		if _, err := m.GenPeer(); err != nil {
			return nil, err
		}
	}
	return m, nil
}

// FullMeshLinked constructs a Mocknet with full mesh of Links.
// This means that all the peers **can** connect to each other
// (not that they already are connected. you can use m.ConnectAll())
func FullMeshLinked(ctx context.Context, n int) (Mocknet, error) {
	m, err := WithNPeers(ctx, n)
	if err != nil {
		return nil, err
	}

	if err := m.LinkAll(); err != nil {
Example #9
0
// package chunk implements streaming block splitters
package chunk

import (
	"io"

	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("chunk")

var DefaultBlockSize int64 = 1024 * 256

type Splitter interface {
	NextBytes() ([]byte, error)
}

type SplitterGen func(r io.Reader) Splitter

func DefaultSplitter(r io.Reader) Splitter {
	return NewSizeSplitter(r, DefaultBlockSize)
}

func SizeSplitterGen(size int64) SplitterGen {
	return func(r io.Reader) Splitter {
		return NewSizeSplitter(r, size)
	}
}

func Chan(s Splitter) (<-chan []byte, <-chan error) {
	out := make(chan []byte)
Example #10
0
	syncds "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
	commands "github.com/djbarber/ipfs-hack/commands"
	core "github.com/djbarber/ipfs-hack/core"
	corehttp "github.com/djbarber/ipfs-hack/core/corehttp"
	corerouting "github.com/djbarber/ipfs-hack/core/corerouting"
	"github.com/djbarber/ipfs-hack/core/coreunix"
	peer "github.com/djbarber/ipfs-hack/p2p/peer"
	"github.com/djbarber/ipfs-hack/repo"
	config "github.com/djbarber/ipfs-hack/repo/config"
	fsrepo "github.com/djbarber/ipfs-hack/repo/fsrepo"
	unit "github.com/djbarber/ipfs-hack/thirdparty/unit"
	ds2 "github.com/djbarber/ipfs-hack/util/datastore2"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var elog = logging.Logger("gc-client")

var (
	cat             = flag.Bool("cat", false, "else add")
	seed            = flag.Int64("seed", 1, "")
	nBitsForKeypair = flag.Int("b", 1024, "number of bits for keypair (if repo is uninitialized)")
)

func main() {
	flag.Parse()
	if err := run(); err != nil {
		fmt.Fprintf(os.Stderr, "error: %s\n", err)
		os.Exit(1)
	}
}
Example #11
0
	swarm "github.com/djbarber/ipfs-hack/p2p/net/swarm"
	protocol "github.com/djbarber/ipfs-hack/p2p/protocol"
	testutil "github.com/djbarber/ipfs-hack/p2p/test/util"
	u "github.com/djbarber/ipfs-hack/util"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"

	ps "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-peerstream"
	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
)

func init() {
	// change the garbage collect timeout for testing.
	ps.GarbageCollectTimeout = 10 * time.Millisecond
}

var log = logging.Logger("reconnect")

func EchoStreamHandler(stream inet.Stream) {
	c := stream.Conn()
	log.Debugf("%s echoing %s", c.LocalPeer(), c.RemotePeer())
	go func() {
		defer stream.Close()
		io.Copy(stream, stream)
	}()
}

type sendChans struct {
	send   chan struct{}
	sent   chan struct{}
	read   chan struct{}
	close_ chan struct{}
Example #12
0
// package kbucket implements a kademlia 'k-bucket' routing table.
package kbucket

import (
	"fmt"
	"sort"
	"sync"
	"time"

	peer "github.com/djbarber/ipfs-hack/p2p/peer"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("table")

// RoutingTable defines the routing table.
type RoutingTable struct {

	// ID of the local peer
	local ID

	// Blanket lock, refine later for better performance
	tabLock sync.RWMutex

	// latency metrics
	metrics peer.Metrics

	// Maximum acceptable latency for peers in this cluster
	maxLatency time.Duration

	// kBuckets define all the fingers to other nodes.
Example #13
0
	"time"

	random "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-random"
	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"

	"github.com/djbarber/ipfs-hack/core"
	coreunix "github.com/djbarber/ipfs-hack/core/coreunix"
	mock "github.com/djbarber/ipfs-hack/core/mock"
	mocknet "github.com/djbarber/ipfs-hack/p2p/net/mock"
	"github.com/djbarber/ipfs-hack/p2p/peer"
	"github.com/djbarber/ipfs-hack/thirdparty/unit"
	testutil "github.com/djbarber/ipfs-hack/util/testutil"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("epictest")

const kSeed = 1

func Test1KBInstantaneous(t *testing.T) {
	conf := testutil.LatencyConfig{
		NetworkLatency:    0,
		RoutingLatency:    0,
		BlockstoreLatency: 0,
	}

	if err := DirectAddCat(RandomBytes(1*unit.KB), conf); err != nil {
		t.Fatal(err)
	}
}
Example #14
0
package queue

import (
	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
	peer "github.com/djbarber/ipfs-hack/p2p/peer"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("peerqueue")

// ChanQueue makes any PeerQueue synchronizable through channels.
type ChanQueue struct {
	Queue   PeerQueue
	EnqChan chan<- peer.ID
	DeqChan <-chan peer.ID
}

// NewChanQueue creates a ChanQueue by wrapping pq.
func NewChanQueue(ctx context.Context, pq PeerQueue) *ChanQueue {
	cq := &ChanQueue{Queue: pq}
	cq.process(ctx)
	return cq
}

func (cq *ChanQueue) process(ctx context.Context) {
	// construct the channels here to be able to use them bidirectionally
	enqChan := make(chan peer.ID)
	deqChan := make(chan peer.ID)

	cq.EnqChan = enqChan
	cq.DeqChan = deqChan
Example #15
0
package addrutil

import (
	"fmt"

	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"

	ma "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
	manet "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
)

var log = logging.Logger("p2p/net/swarm/addr")

// SupportedTransportStrings is the list of supported transports for the swarm.
// These are strings of encapsulated multiaddr protocols. E.g.:
//   /ip4/tcp
var SupportedTransportStrings = []string{
	"/ip4/tcp",
	"/ip6/tcp",
	// "/ip4/udp/utp", disabled because the lib is broken
	// "/ip6/udp/utp", disabled because the lib is broken
	// "/ip4/udp/udt", disabled because the lib doesnt work on arm
	// "/ip6/udp/udt", disabled because the lib doesnt work on arm
}

// SupportedTransportProtocols is the list of supported transports for the swarm.
// These are []ma.Protocol lists. Populated at runtime from SupportedTransportStrings
var SupportedTransportProtocols = [][]ma.Protocol{}

func init() {
Example #16
0
	"math/rand"
	"testing"
	"time"

	host "github.com/djbarber/ipfs-hack/p2p/host"
	inet "github.com/djbarber/ipfs-hack/p2p/net"
	peer "github.com/djbarber/ipfs-hack/p2p/peer"
	protocol "github.com/djbarber/ipfs-hack/p2p/protocol"
	testutil "github.com/djbarber/ipfs-hack/p2p/test/util"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"

	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
	u "github.com/djbarber/ipfs-hack/util"
)

var log = logging.Logger("backpressure")

// TestBackpressureStreamHandler tests whether mux handler
// ratelimiting works. Meaning, since the handler is sequential
// it should block senders.
//
// Important note: spdystream (which peerstream uses) has a set
// of n workers (n=spdsystream.FRAME_WORKERS) which handle new
// frames, including those starting new streams. So all of them
// can be in the handler at one time. Also, the sending side
// does not rate limit unless we call stream.Wait()
//
//
// Note: right now, this happens muxer-wide. the muxer should
// learn to flow control, so handlers cant block each other.
func TestBackpressureStreamHandler(t *testing.T) {
Example #17
0
	trickle "github.com/djbarber/ipfs-hack/importer/trickle"
	mdag "github.com/djbarber/ipfs-hack/merkledag"
	pin "github.com/djbarber/ipfs-hack/pin"
	ft "github.com/djbarber/ipfs-hack/unixfs"
	uio "github.com/djbarber/ipfs-hack/unixfs/io"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var ErrSeekFail = errors.New("failed to seek properly")
var ErrSeekEndNotImpl = errors.New("SEEK_END currently not implemented")
var ErrUnrecognizedWhence = errors.New("unrecognized whence")

// 2MB
var writebufferSize = 1 << 21

var log = logging.Logger("dagio")

// DagModifier is the only struct licensed and able to correctly
// perform surgery on a DAG 'file'
// Dear god, please rename this to something more pleasant
type DagModifier struct {
	dagserv mdag.DAGService
	curNode *mdag.Node
	mp      pin.ManualPinner

	splitter   chunk.SplitterGen
	ctx        context.Context
	readCancel func()

	writeStart uint64
	curWrOff   uint64
Example #18
0
package record

import (
	"bytes"

	proto "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/gogo/protobuf/proto"

	key "github.com/djbarber/ipfs-hack/blocks/key"
	dag "github.com/djbarber/ipfs-hack/merkledag"
	ci "github.com/djbarber/ipfs-hack/p2p/crypto"
	pb "github.com/djbarber/ipfs-hack/routing/dht/pb"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var _ = dag.FetchGraph
var log = logging.Logger("routing/record")

// MakePutRecord creates and signs a dht record for the given key/value pair
func MakePutRecord(sk ci.PrivKey, key key.Key, value []byte, sign bool) (*pb.Record, error) {
	record := new(pb.Record)

	record.Key = proto.String(string(key))
	record.Value = value

	pkh, err := sk.GetPublic().Hash()
	if err != nil {
		return nil, err
	}

	record.Author = proto.String(string(pkh))
	if sign {
Example #19
0
import (
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"os"
	"path/filepath"

	"github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/facebookgo/atomicfile"
	"github.com/djbarber/ipfs-hack/repo/config"
	"github.com/djbarber/ipfs-hack/util"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("fsrepo")

// ReadConfigFile reads the config from `filename` into `cfg`.
func ReadConfigFile(filename string, cfg interface{}) error {
	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer f.Close()
	if err := json.NewDecoder(f).Decode(cfg); err != nil {
		return fmt.Errorf("Failure to decode config: %s", err)
	}
	return nil
}

// WriteConfigFile writes the config from `cfg` into `filename`.
Example #20
0
	"sync"
	"time"

	ggio "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/gogo/protobuf/io"
	proto "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
	ctxio "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-context/io"
	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
	pb "github.com/djbarber/ipfs-hack/diagnostics/pb"
	host "github.com/djbarber/ipfs-hack/p2p/host"
	inet "github.com/djbarber/ipfs-hack/p2p/net"
	peer "github.com/djbarber/ipfs-hack/p2p/peer"
	protocol "github.com/djbarber/ipfs-hack/p2p/protocol"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("diagnostics")

// ProtocolDiag is the diagnostics protocol.ID
var ProtocolDiag protocol.ID = "/ipfs/diagnostics"

var ErrAlreadyRunning = errors.New("diagnostic with that ID already running")

const ResponseTimeout = time.Second * 10
const HopTimeoutDecrement = time.Second * 2

// Diagnostics is a net service that manages requesting and responding to diagnostic
// requests
type Diagnostics struct {
	host host.Host
	self peer.ID
Example #21
0
	"crypto/hmac"
	"crypto/rand"
	"crypto/rsa"
	"crypto/sha1"
	"crypto/sha256"
	"crypto/sha512"
	"hash"

	proto "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/gogo/protobuf/proto"

	pb "github.com/djbarber/ipfs-hack/p2p/crypto/pb"
	u "github.com/djbarber/ipfs-hack/util"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("crypto")

var ErrBadKeyType = errors.New("invalid or unsupported key type")

const (
	RSA = iota
)

// Key represents a crypto key that can be compared to another key
type Key interface {
	// Bytes returns a serialized, storeable representation of this key
	Bytes() ([]byte, error)

	// Hash returns the hash of this key
	Hash() ([]byte, error)
Example #22
0
import (
	"bytes"
	"errors"
	"io"
	"time"

	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"

	host "github.com/djbarber/ipfs-hack/p2p/host"
	inet "github.com/djbarber/ipfs-hack/p2p/net"
	peer "github.com/djbarber/ipfs-hack/p2p/peer"
	u "github.com/djbarber/ipfs-hack/util"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("ping")

const PingSize = 32

const ID = "/ipfs/ping"

type PingService struct {
	Host host.Host
}

func NewPingService(h host.Host) *PingService {
	ps := &PingService{h}
	h.SetStreamHandler(ID, ps.PingHandler)
	return ps
}
Example #23
0
	"io"
	"net/http"
	"net/url"
	"os"
	"runtime"
	"strconv"
	"strings"

	cors "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/rs/cors"
	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"

	cmds "github.com/djbarber/ipfs-hack/commands"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("commands/http")

// the internal handler for the API
type internalHandler struct {
	ctx  cmds.Context
	root *cmds.Command
	cfg  *ServerConfig
}

// The Handler struct is funny because we want to wrap our internal handler
// with CORS while keeping our fields.
type Handler struct {
	internalHandler
	corsHandler http.Handler
}
Example #24
0
// package merkledag implements the ipfs Merkle DAG datastructures.
package merkledag

import (
	"fmt"
	"sync"

	"github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
	blocks "github.com/djbarber/ipfs-hack/blocks"
	key "github.com/djbarber/ipfs-hack/blocks/key"
	bserv "github.com/djbarber/ipfs-hack/blockservice"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("merkledag")
var ErrNotFound = fmt.Errorf("merkledag: not found")

// DAGService is an IPFS Merkle DAG service.
type DAGService interface {
	Add(*Node) (key.Key, error)
	AddRecursive(*Node) error
	Get(context.Context, key.Key) (*Node, error)
	Remove(*Node) error

	// GetDAG returns, in order, all the single leve child
	// nodes of the passed in node.
	GetDAG(context.Context, *Node) []NodeGetter
	GetNodes(context.Context, []key.Key) []NodeGetter

	Batch() *Batch
}
Example #25
0
package protocol

import (
	"fmt"
	"io"
	"sync"

	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"
	inet "github.com/djbarber/ipfs-hack/p2p/net"
	lgbl "github.com/djbarber/ipfs-hack/util/eventlog/loggables"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("net/mux")

type streamHandlerMap map[ID]inet.StreamHandler

// Mux provides simple stream multixplexing.
// It helps you precisely when:
//  * You have many streams
//  * You have function handlers
//
// It contains the handlers for each protocol accepted.
// It dispatches handlers for streams opened by remote peers.
type Mux struct {
	lock           sync.RWMutex
	handlers       streamHandlerMap
	defaultHandler inet.StreamHandler
}

func NewMux() *Mux {
Example #26
0
package dht_pb

import (
	ma "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"

	key "github.com/djbarber/ipfs-hack/blocks/key"
	inet "github.com/djbarber/ipfs-hack/p2p/net"
	peer "github.com/djbarber/ipfs-hack/p2p/peer"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("dht.pb")

type PeerRoutingInfo struct {
	peer.PeerInfo
	inet.Connectedness
}

// NewMessage constructs a new dht message with given type, key, and level
func NewMessage(typ Message_MessageType, key string, level int) *Message {
	m := &Message{
		Type: &typ,
		Key:  &key,
	}
	m.SetClusterLevel(level)
	return m
}

func peerRoutingInfoToPBPeer(p PeerRoutingInfo) *Message_Peer {
	pbp := new(Message_Peer)
Example #27
0
	ggio "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/gogo/protobuf/io"
	ma "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
	context "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"

	mstream "github.com/djbarber/ipfs-hack/metrics/stream"
	host "github.com/djbarber/ipfs-hack/p2p/host"
	inet "github.com/djbarber/ipfs-hack/p2p/net"
	peer "github.com/djbarber/ipfs-hack/p2p/peer"
	protocol "github.com/djbarber/ipfs-hack/p2p/protocol"
	pb "github.com/djbarber/ipfs-hack/p2p/protocol/identify/pb"
	config "github.com/djbarber/ipfs-hack/repo/config"
	lgbl "github.com/djbarber/ipfs-hack/util/eventlog/loggables"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("net/identify")

// ID is the protocol.ID of the Identify Service.
const ID protocol.ID = "/ipfs/identify"

// IpfsVersion holds the current protocol version for a client running this code
// TODO(jbenet): fix the versioning mess.
const IpfsVersion = "ipfs/0.1.0"
const ClientVersion = "go-ipfs/" + config.CurrentVersionNumber

// IDService is a structure that implements ProtocolIdentify.
// It is a trivial service that gives the other peer some
// useful information about the local peer. A sort of hello.
//
// The IDService sends:
//  * Our IPFS Protocol Version
Example #28
0
// package mount provides a simple abstraction around a mount point
package mount

import (
	"fmt"
	"io"
	"os/exec"
	"runtime"
	"time"

	goprocess "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/goprocess"

	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("mount")

var MountTimeout = time.Second * 5

// Mount represents a filesystem mount
type Mount interface {
	// MountPoint is the path at which this mount is mounted
	MountPoint() string

	// Unmounts the mount
	Unmount() error

	// Process returns the mount's Process to be able to link it
	// to other processes. Unmount upon closing.
	Process() goprocess.Process
}
Example #29
0
import (
	"fmt"

	proto "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
	mh "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multihash"
	"github.com/djbarber/ipfs-hack/Godeps/_workspace/src/golang.org/x/net/context"

	key "github.com/djbarber/ipfs-hack/blocks/key"
	pb "github.com/djbarber/ipfs-hack/namesys/pb"
	path "github.com/djbarber/ipfs-hack/path"
	routing "github.com/djbarber/ipfs-hack/routing"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("namesys")

// routingResolver implements NSResolver for the main IPFS SFS-like naming
type routingResolver struct {
	routing routing.IpfsRouting
}

// NewRoutingResolver constructs a name resolver using the IPFS Routing system
// to implement SFS-like naming on top.
func NewRoutingResolver(route routing.IpfsRouting) Resolver {
	if route == nil {
		panic("attempt to create resolver with nil routing system")
	}

	return &routingResolver{routing: route}
}
Example #30
0
import (
	"encoding/hex"
	"encoding/json"
	"fmt"
	"strings"

	b58 "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-base58"
	ma "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
	mh "github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/jbenet/go-multihash"

	ic "github.com/djbarber/ipfs-hack/p2p/crypto"
	u "github.com/djbarber/ipfs-hack/util"
	logging "github.com/djbarber/ipfs-hack/vendor/go-log-v1.0.0"
)

var log = logging.Logger("peer")

// ID represents the identity of a peer.
type ID string

// Pretty returns a b58-encoded string of the ID
func (id ID) Pretty() string {
	return IDB58Encode(id)
}

func (id ID) Loggable() map[string]interface{} {
	return map[string]interface{}{
		"peerID": id.Pretty(),
	}
}