-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started on dirtylist packet etc. Diagram.
- Loading branch information
Showing
10 changed files
with
415 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package modules | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/loopholelabs/silo/pkg/storage" | ||
) | ||
|
||
/** | ||
* | ||
*/ | ||
|
||
type ReadOnlyGate struct { | ||
prov storage.StorageProvider | ||
lock *sync.Cond | ||
locked bool | ||
} | ||
|
||
func NewReadOnlyGate(prov storage.StorageProvider) *Lockable { | ||
return &Lockable{ | ||
prov: prov, | ||
lock: sync.NewCond(&sync.Mutex{}), | ||
locked: false, | ||
} | ||
} | ||
|
||
func (i *ReadOnlyGate) ReadAt(p []byte, off int64) (n int, err error) { | ||
return i.prov.ReadAt(p, off) | ||
} | ||
|
||
func (i *ReadOnlyGate) WriteAt(p []byte, off int64) (n int, err error) { | ||
i.lock.L.Lock() | ||
if i.locked { | ||
i.lock.Wait() | ||
} | ||
i.lock.L.Unlock() | ||
|
||
return i.prov.WriteAt(p, off) | ||
} | ||
|
||
func (i *ReadOnlyGate) Flush() error { | ||
return i.prov.Flush() | ||
} | ||
|
||
func (i *ReadOnlyGate) Size() uint64 { | ||
return i.prov.Size() | ||
} | ||
|
||
func (i *ReadOnlyGate) Unlock() { | ||
i.lock.L.Lock() | ||
i.locked = false | ||
i.lock.Broadcast() | ||
i.lock.L.Unlock() | ||
} | ||
|
||
func (i *ReadOnlyGate) Lock() { | ||
i.lock.L.Lock() | ||
i.locked = true | ||
i.lock.L.Unlock() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package protocol | ||
|
||
import ( | ||
"encoding/binary" | ||
"errors" | ||
) | ||
|
||
func EncodeDirtyList(blocks []uint32) []byte { | ||
buff := make([]byte, 1+4+4*len(blocks)) | ||
buff[0] = COMMAND_DIRTY_LIST | ||
binary.LittleEndian.PutUint32(buff[1:], uint32(len(blocks))) | ||
for i, v := range blocks { | ||
binary.LittleEndian.PutUint32(buff[(5+i*4):], v) | ||
} | ||
return buff | ||
} | ||
|
||
func DecodeDirtyList(buff []byte) ([]uint32, error) { | ||
if buff == nil || len(buff) < 9 || buff[0] != COMMAND_DIRTY_LIST { | ||
return nil, errors.New("Invalid packet") | ||
} | ||
length := binary.LittleEndian.Uint32(buff[1:]) | ||
blocks := make([]uint32, length) | ||
for i := 0; i < int(length); i++ { | ||
blocks[i] = binary.LittleEndian.Uint32(buff[(5 + i*4):]) | ||
} | ||
return blocks, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters