Skip to content

Commit

Permalink
almost there!
Browse files Browse the repository at this point in the history
  • Loading branch information
marinhero committed Feb 19, 2015
1 parent 0a6dfda commit 2b2ad91
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
12 changes: 6 additions & 6 deletions UDPush/UDPush.go
Expand Up @@ -3,7 +3,7 @@
** Author: Marin Alcaraz
** Mail <marin.alcaraz@gmail.com>
** Started on Mon Feb 09 14:36:00 2015 Marin Alcaraz
** Last update Thu Feb 19 14:41:39 2015 Marin Alcaraz
** Last update Thu Feb 19 15:45:08 2015 Marin Alcaraz
*/

package UDPush
Expand Down Expand Up @@ -96,10 +96,10 @@ func (e *Pusher) Detach(w Watcher) (err error) {
//Notify Tell the watcher {clientID} to update
func (e *Pusher) Notify(sessionkey string) {
for _, k := range e.Watchers {
//if k.SessionKey == sessionkey {
k.Update()
k.Action = true
//}
if k.SessionKey != sessionkey {
k.Update()
k.Action = true
}
}
}

Expand All @@ -119,7 +119,7 @@ func (e *Pusher) ShowWatchers() {
func (w *Watcher) Update() {
w.Action = true
fits := w.SessionKey[:2]
fmt.Println("[!]Attempting to update watcher: %s", fits)
fmt.Println("[!] Attempting to update watcher: %s", fits)
writen, err := w.Connection.Write([]byte("Y"))
if writen != len([]byte("Y")) {
fmt.Println("[!]Error writting: unable to write")
Expand Down
1 change: 1 addition & 0 deletions boxtools/boxtools.go
Expand Up @@ -390,6 +390,7 @@ func WriteFileActionsToDatabase(fileActions []structs.FileAction,
return outPutFileActions, err
}
for _, fileAction := range fileActions {
fileAction.ClientId = client.Id
file, err := FindFile(fileAction.File.Hash, fileAction.File.Path, user)
if err != nil {
return outPutFileActions, err
Expand Down
6 changes: 1 addition & 5 deletions client/api/api.go
Expand Up @@ -67,19 +67,15 @@ func (c *Api) SendFileActionsToServer(
//}

contents, _ := ioutil.ReadAll(resp.Body)
fmt.Println(contents)
if err != nil {
fmt.Println("[*]")
return
}

if resp.StatusCode != http.StatusOK {
err = fmt.Errorf(string(contents))
return
}
err = json.Unmarshal(contents, &filesToUpload)
if err != nil {
fmt.Println("[-]")
return
}
return
Expand Down Expand Up @@ -141,7 +137,7 @@ func (c *Api) DownloadClientFileActions(lastId int64) (
ApiEndpoint+"clients/",
url.Values{
"SessionKey": {c.SessionKey},
"lastID": {lastIdString},
"lastId": {lastIdString},
},
)
if err != nil {
Expand Down
16 changes: 11 additions & 5 deletions client/client.go
Expand Up @@ -145,9 +145,10 @@ func createServerStateChange(fa structs.FileAction) (change structs.StateChange)
func serverActions(UDPing <-chan bool, fileActionIdPath string,
initScanDone <-chan struct{}) (out chan structs.StateChange,
errorChan chan interface{}, err error) {
out = make(chan structs.StateChange)
fileActionId, err := fetchFileActionID(fileActionIdPath)
if err != nil {
panic("Couldn't properly read fileActionId from given path")
panic("Couldn't properly read fil eActionId from given path")
}

go func() {
Expand All @@ -156,23 +157,20 @@ func serverActions(UDPing <-chan bool, fileActionIdPath string,
<-UDPing
fmt.Println("-----------------PING RECIEVED--------------------")
// these return values are obviously wrong right now
fmt.Println("1")
fmt.Println("File aCTION ID", fileActionId)
clientFileActionResponse, err := client.DownloadClientFileActions(
fileActionId)
fmt.Println("2")
// need to rethink errors, assumption of a statechange is invalid
if err != nil {
fmt.Println(err)
writeError(err, structs.StateChange{}, "serverActions")
}
fileActionId = clientFileActionResponse.LastId
fmt.Println("3")
for _, fileAction := range clientFileActionResponse.FileActions {
change := createServerStateChange(fileAction)
out <- change
fmt.Println("loop")
}
fmt.Println("4")
err = writeFileActionIDToLocalFile(fileActionId, fileActionIdPath)
if err != nil {
fmt.Println("Couldn't write fileActionId to path : ",
Expand Down Expand Up @@ -218,12 +216,16 @@ func fanActionsIn(initActions <-chan structs.StateChange,
out := make(chan structs.StateChange)
go func() {
for {
fmt.Println("FanActions")
select {
case stateChange := <-initActions:
fmt.Println("fanActions inside the stateChange := <-initActions")
out <- stateChange
case stateChange := <-watcherActions:
fmt.Println("fanActions inside the stateChange := <-WatcherActions")
out <- stateChange
case stateChange := <-serverActions:
fmt.Println("fanActions inside the stateChange := <-serverActions")
out <- stateChange
}
}
Expand Down Expand Up @@ -454,6 +456,7 @@ func serverDeleter(change structs.StateChange) {
}

func downloader(change structs.StateChange) {
fmt.Println("begin")
select {
case <-change.Quit:
gracefulQuit(change)
Expand Down Expand Up @@ -488,6 +491,7 @@ func downloader(change structs.StateChange) {
}
}
}
fmt.Println("look")
return
}

Expand Down Expand Up @@ -548,6 +552,7 @@ func stephen(goboxFileSystemStateFile string, stateChanges <-chan structs.StateC
delete(quitChannels, fa.File.Path)
fileSystemState[fa.File.Path] = fa.File
case change := <-stateChanges:
fmt.Printf("Stephen says: |%s|", change)
if currentAction, found := quitChannels[change.File.Path]; found {
// tell goroutine branch to quit
currentAction.Quit <- true
Expand Down Expand Up @@ -576,6 +581,7 @@ func stephen(goboxFileSystemStateFile string, stateChanges <-chan structs.StateC
if change.IsLocal {
go hasher(change)
} else {
fmt.Println("[!]Attempting download...")
go downloader(change)
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions hola.txt
@@ -0,0 +1,3 @@
Hola
Hola
Hola
9 changes: 1 addition & 8 deletions server/api/api.go
Expand Up @@ -142,14 +142,7 @@ func FileActionsHandler(w http.ResponseWriter, req *http.Request,
return
}

var clients []structs.Client
model.DB.Where("user_id = ?", user.Id).
Not("id = ?", client.Id).
Find(&clients)

for _, value := range clients {
Pusher.Notify(value.SessionKey)
}
Pusher.Notify(client.SessionKey)

errs := boxtools.ApplyFileActionsToFileSystemFileTable(fileActions, user)
if len(errs) != 0 {
Expand Down

0 comments on commit 2b2ad91

Please sign in to comment.