@@ -10,7 +10,6 @@ import (
1010 "github.com/named-data/ndnd/std/engine"
1111 "github.com/named-data/ndnd/std/log"
1212 "github.com/named-data/ndnd/std/ndn"
13- spec_svs "github.com/named-data/ndnd/std/ndn/svs/v3"
1413 "github.com/named-data/ndnd/std/ndn/svs_ps"
1514 "github.com/named-data/ndnd/std/object"
1615 ndn_sync "github.com/named-data/ndnd/std/sync"
@@ -74,7 +73,7 @@ func main() {
7473 defer client .Stop ()
7574
7675 // Create a new SVS ALO instance
77- svsalo = ndn_sync .NewSvsALO (ndn_sync.SvsAloOpts {
76+ svsalo , err = ndn_sync .NewSvsALO (ndn_sync.SvsAloOpts {
7877 // Name is the name of the node
7978 Name : name ,
8079
@@ -95,6 +94,9 @@ func main() {
9594 Threshold : 10 ,
9695 },
9796 })
97+ if err != nil {
98+ panic (err )
99+ }
98100
99101 // OnError gets called when we get an error from the SVS ALO instance.
100102 svsalo .SetOnError (func (err error ) {
@@ -190,30 +192,21 @@ func publish(content []byte) {
190192 commitState (state )
191193}
192194
193- func commitState (state * spec_svs. InstanceState ) {
195+ func commitState (state enc. Wire ) {
194196 // Once a publication is processed, ideally the application should persist
195197 // it's own state and the state of the Sync group *atomically*.
196198 //
197199 // Applications can use their own data structures to store the state.
198- // In this example, we use the object store to persist the state.
199- store .Put (group , 0 , state .Encode (). Join ())
200+ // In this example, we use the NDN object store to persist the state.
201+ store .Put (group , 0 , state .Join ())
200202}
201203
202- func readState () * spec_svs. InstanceState {
204+ func readState () enc. Wire {
203205 // Read the state from the object store
204206 // See commitState for more information
205207 stateWire , err := store .Get (group , false )
206208 if err != nil {
207- log .Error (nil , "Unable to get state from object store" , "err" , err )
208- os .Exit (1 )
209- }
210- if stateWire != nil {
211- state , err := spec_svs .ParseInstanceState (enc .NewBufferView (stateWire ), true )
212- if err != nil {
213- log .Error (nil , "Unable to parse state from object store" , "err" , err )
214- os .Exit (1 )
215- }
216- return state
209+ panic ("unable to get state (store is broken)" )
217210 }
218- return nil
211+ return enc. Wire { stateWire }
219212}
0 commit comments