fix(core) patiently convince the core to compile
=)
Brian Tiger Chow committed
Sep 17, 2014 at 13:57 UTC
547f9e1cf69885e84ee023e2e2a0fb2c721dcbcf
1 file changed
+25
-14
core/core.go
+25
-14
@@ -47,7 +47,7 @@ type IpfsNode struct {
47
Routing routing.IpfsRouting
48
49
// the block exchange + strategy (bitswap)
50
- BitSwap bitswap.BitSwap
50
+ BitSwap bitswap.Exchange
51
52
// the block service, get/add blocks.
53
Blocks *bserv.BlockService
@@ -80,37 +80,48 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
80
81
peerstore := peer.NewPeerstore()
82
83
+ // FIXME(brian): This is a bit dangerous. If any of the vars declared in
84
+ // this block are assigned inside of the "if online" block using the ":="
85
+ // declaration syntax, the compiler permits re-declaration. This is rather
86
+ // undesirable
87
var (
84
- net *inet.Network
88
+ net inet.Network
89
// TODO: refactor so we can use IpfsRouting interface instead of being DHT-specific
86
- route *dht.IpfsDHT
90
+ route *dht.IpfsDHT
91
+ exchangeSession bitswap.Exchange
92
)
93
94
if online {
95
// add protocol services here.
96
ctx := context.TODO() // derive this from a higher context.
97
93
- dhts := netservice.Service(nil) // nil handler for now, need to patch it
94
- if err := dhts.Start(ctx); err != nil {
98
+ dhtService := netservice.NewService(nil) // nil handler for now, need to patch it
99
+ exchangeService := netservice.NewService(nil) // nil handler for now, need to patch it
100
+
101
+ if err := dhtService.Start(ctx); err != nil {
102
+ return nil, err
103
+ }
104
+ if err := exchangeService.Start(ctx); err != nil {
105
return nil, err
106
}
107
98
- net, err := inet.NewIpfsNetwork(context.TODO(), local, &mux.ProtocolMap{
99
- netservice.ProtocolID_Routing: dhtService,
100
- // netservice.ProtocolID_Bitswap: bitswapService,
108
+ net, err = inet.NewIpfsNetwork(context.TODO(), local, &mux.ProtocolMap{
109
+ mux.ProtocolID_Routing: dhtService,
110
+ mux.ProtocolID_Exchange: exchangeService,
111
})
112
if err != nil {
113
return nil, err
114
}
115
106
- route = dht.NewDHT(local, peerstore, net, dhts, d)
107
- dhts.Handler = route // wire the handler to the service.
116
+ route = dht.NewDHT(local, peerstore, net, dhtService, d)
117
+ // TODO(brian): perform this inside NewDHT factory method
118
+ dhtService.Handler = route // wire the handler to the service.
119
120
// TODO(brian): pass a context to DHT for its async operations
121
route.Start()
122
123
// TODO(brian): pass a context to bs for its async operations
113
- bitswapSession := bitswap.NewSession(context.TODO(), local, d, route)
124
+ exchangeSession = bitswap.NewSession(ctx, exchangeService, local, d, route)
125
126
// TODO(brian): pass a context to initConnections
127
go initConnections(cfg, route)
@@ -118,7 +129,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
129
130
// TODO(brian): when offline instantiate the BlockService with a bitswap
131
// session that simply doesn't return blocks
121
- bs, err := bserv.NewBlockService(d, bitswapSession)
132
+ bs, err := bserv.NewBlockService(d, exchangeSession)
133
if err != nil {
134
return nil, err
135
}
@@ -127,12 +138,12 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
138
139
return &IpfsNode{
140
Config: cfg,
130
- Peerstore: peerstore,
141
+ Peerstore: &peerstore,
142
Datastore: d,
143
Blocks: bs,
144
DAG: dag,
145
Resolver: &path.Resolver{DAG: dag},
135
- BitSwap: bitswapSession,
146
+ BitSwap: exchangeSession,
147
Identity: local,
148
Routing: route,
149
}, nil