summaryrefslogtreecommitdiff
path: root/src/hub/src/spreadspace.org/sfive/s5store.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/hub/src/spreadspace.org/sfive/s5store.go')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index 8dda6af..567cadc 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -49,7 +49,7 @@ const (
)
var (
- storeBuckets = []string{latestUpdatesBn, hubUuidsFwdBn, hubUuidsRevBn, dataUpdatesBn,
+ storeBuckets = []string{latestUpdatesBn, hubUuidsFwdBn, hubUuidsRevBn, updatesBn,
sourcesFwdBn, sourcesRevBn, clientDataBn, userAgentsFwdBn, userAgentsRevBn}
)
@@ -240,8 +240,8 @@ func (st Store) insertNewSource(tx *bolt.Tx, src sourceDb) (srcId int, err error
return srcId, err
}
-func (st Store) insertDataUpdate(tx *bolt.Tx, du dataUpdateDb) (duId int, err error) {
- b := tx.Bucket([]byte(dataUpdatesBn))
+func (st Store) insertUpdate(tx *bolt.Tx, du updateDb) (duId int, err error) {
+ b := tx.Bucket([]byte(updatesBn))
b.FillPercent = 1.0 // we only do appends
next, _ := b.NextSequence()
@@ -278,7 +278,7 @@ func (st Store) insertNewUserAgent(tx *bolt.Tx, ua string) (uaId int, err error)
return uaId, err
}
-func (st Store) insertClientData(tx *bolt.Tx, duId int, cd []ClientData) error {
+func (st Store) insertClient(tx *bolt.Tx, duId int, cd []Client) error {
if len(cd) == 0 {
return nil
}
@@ -315,8 +315,8 @@ func (st Store) setLastUpdateForUuid(tx *bolt.Tx, uuid string, duId int) error {
// Split up the multidimensional dataupdate and append all the key-value pairs
-func (st Store) appendItem(tx *bolt.Tx, update DataUpdateFull) (duId int, err error) {
- du := NewDataUpdateDb(update)
+func (st Store) appendItem(tx *bolt.Tx, update UpdateFull) (duId int, err error) {
+ du := NewUpdateDb(update)
src := NewSourceDb(update)
if du.SourceHubId, err = st.insertNewHub(tx, update.SourceHubUuid); err != nil {
@@ -325,25 +325,25 @@ func (st Store) appendItem(tx *bolt.Tx, update DataUpdateFull) (duId int, err er
if du.SourceId, err = st.insertNewSource(tx, src); err != nil {
return
}
- if duId, err = st.insertDataUpdate(tx, du); err != nil {
+ if duId, err = st.insertUpdate(tx, du); err != nil {
return
}
- if err = st.insertClientData(tx, duId, update.Data.Clients); err != nil {
+ if err = st.insertClient(tx, duId, update.Data.Clients); err != nil {
return
}
if update.SourceHubUuid != "" {
- err = st.setLastUpdateForUuid(tx, update.SourceHubUuid, du.SourceHubDataUpdateId)
+ err = st.setLastUpdateForUuid(tx, update.SourceHubUuid, du.SourceHubUpdateId)
}
if update.ForwardHubUuid != "" {
- err = st.setLastUpdateForUuid(tx, update.ForwardHubUuid, update.ForwardHubDataUpdateId)
+ err = st.setLastUpdateForUuid(tx, update.ForwardHubUuid, update.ForwardHubUpdateId)
}
return
}
// Public Append Interface
-func (st Store) AppendMany(updates []DataUpdateFull) (err error) {
+func (st Store) AppendMany(updates []UpdateFull) (err error) {
if st.readOnly {
return ErrReadOnly
}
@@ -357,8 +357,8 @@ func (st Store) AppendMany(updates []DataUpdateFull) (err error) {
})
}
-func (st Store) Append(update DataUpdateFull) (err error) {
- return st.AppendMany([]DataUpdateFull{update})
+func (st Store) Append(update UpdateFull) (err error) {
+ return st.AppendMany([]UpdateFull{update})
}
//
@@ -390,7 +390,7 @@ func (st Store) getSource(tx *bolt.Tx, id int) (res sourceDb, err error) {
return
}
-func (st Store) getClients(tx *bolt.Tx, id int) (res []ClientData, err error) {
+func (st Store) getClients(tx *bolt.Tx, id int) (res []Client, err error) {
bc := tx.Bucket([]byte(clientDataBn))
bu := tx.Bucket([]byte(userAgentsRevBn))
@@ -403,7 +403,7 @@ func (st Store) getClients(tx *bolt.Tx, id int) (res []ClientData, err error) {
return
}
for _, c := range data {
- cd := ClientData{Ip: c.Ip, BytesSent: c.BytesSent}
+ cd := Client{Ip: c.Ip, BytesSent: c.BytesSent}
ua := bu.Get(itob(c.UserAgentId))
if ua != nil {
cd.UserAgent = string(ua)
@@ -415,8 +415,8 @@ func (st Store) getClients(tx *bolt.Tx, id int) (res []ClientData, err error) {
// fetch all the key-value pairs and merge them into the multidimensional dataupdate
-func (st Store) fetchItem(tx *bolt.Tx, duId int, du dataUpdateDb) (res DataUpdateFull, err error) {
- res.CopyFromDataUpdateDb(du, st.getHub(tx, du.SourceHubId), st.hubUuid, duId)
+func (st Store) fetchItem(tx *bolt.Tx, duId int, du updateDb) (res UpdateFull, err error) {
+ res.CopyFromUpdateDb(du, st.getHub(tx, du.SourceHubId), st.hubUuid, duId)
var src sourceDb
if src, err = st.getSource(tx, du.SourceId); err != nil {
return
@@ -430,8 +430,8 @@ func (st Store) fetchItem(tx *bolt.Tx, duId int, du dataUpdateDb) (res DataUpdat
// Public Fetch Interface
-func (st Store) GetUpdatesAfter(id, limit int) (res []DataUpdateFull, err error) {
- res = []DataUpdateFull{}
+func (st Store) GetUpdatesAfter(id, limit int) (res []UpdateFull, err error) {
+ res = []UpdateFull{}
if id < 0 { // TODO: interpret negative values as last x values
id = 0
}
@@ -442,7 +442,7 @@ func (st Store) GetUpdatesAfter(id, limit int) (res []DataUpdateFull, err error)
limit = StoreGetUpdatesLimit
}
err = st.db.View(func(tx *bolt.Tx) error {
- c := tx.Bucket([]byte(dataUpdatesBn)).Cursor()
+ c := tx.Bucket([]byte(updatesBn)).Cursor()
k, v := c.Seek(itob(id))
if k == nil {
return nil
@@ -451,7 +451,7 @@ func (st Store) GetUpdatesAfter(id, limit int) (res []DataUpdateFull, err error)
k, v = c.Next()
}
for ; k != nil; k, v = c.Next() {
- var d dataUpdateDb
+ var d updateDb
if err := json.Unmarshal(v, &d); err != nil {
return err
}
@@ -470,16 +470,16 @@ func (st Store) GetUpdatesAfter(id, limit int) (res []DataUpdateFull, err error)
return
}
-func (st Store) GetUpdate(id int) (res DataUpdateFull, err error) {
+func (st Store) GetUpdate(id int) (res UpdateFull, err error) {
err = st.db.View(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte(dataUpdatesBn))
+ b := tx.Bucket([]byte(updatesBn))
jsonData := b.Get(itob(id))
if jsonData == nil {
return ErrNotFound
}
- var d dataUpdateDb
+ var d updateDb
if err := json.Unmarshal(jsonData, &d); err != nil {
return err
}
@@ -503,7 +503,7 @@ func (st Store) GetHubUuid() string {
func (st Store) GetLastUpdateId() (updateId int, err error) {
err = st.db.View(func(tx *bolt.Tx) error {
- updateId = int(tx.Bucket([]byte(dataUpdatesBn)).Sequence())
+ updateId = int(tx.Bucket([]byte(updatesBn)).Sequence())
return nil
})
return
@@ -537,8 +537,8 @@ func (st Store) GetHubs() (res []string, err error) {
return
}
-func (st Store) GetSources() (res []SourceId, err error) {
- res = []SourceId{}
+func (st Store) GetSources() (res []Source, err error) {
+ res = []Source{}
err = st.db.View(func(tx *bolt.Tx) error {
c := tx.Bucket([]byte(sourcesRevBn)).Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
@@ -546,7 +546,7 @@ func (st Store) GetSources() (res []SourceId, err error) {
if err := json.Unmarshal(v, &s); err != nil {
return err
}
- var src SourceId
+ var src Source
src.CopyFromSourceDb(s)
res = append(res, src)
}