| 42 | } |
| 43 | |
| 44 | func initStorage(dbFile string) (stor *LocalStorage, err error) { |
| 45 | var st *storage.Storage |
| 46 | if st, err = storage.New(dbFile); err != nil { |
| 47 | return |
| 48 | } |
| 49 | //TODO(auxten): try BLOB for `id`, to performance test |
| 50 | _, err = st.Exec(context.Background(), []storage.Query{ |
| 51 | { |
| 52 | Pattern: "CREATE TABLE IF NOT EXISTS `dht` (`id` TEXT NOT NULL PRIMARY KEY, `node` BLOB);", |
| 53 | }, |
| 54 | }) |
| 55 | if err != nil { |
| 56 | wd, _ := os.Getwd() |
| 57 | log.WithField("file", utils.FJ(wd, dbFile)).WithError(err).Error("create dht table failed") |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | stor = &LocalStorage{ |
| 62 | Storage: st, |
| 63 | } |
| 64 | |
| 65 | return |
| 66 | } |
| 67 | |
| 68 | // SetNode handles dht storage node update. |
| 69 | func (s *LocalStorage) SetNode(node *proto.Node) (err error) { |