Skip to content

Commit

Permalink
dockerfile for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
therealpaulgg committed Feb 21, 2024
1 parent 4789503 commit b36159e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 16 deletions.
42 changes: 42 additions & 0 deletions docker-compose-debug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3.3'
services:
ssh-sync-server:
restart: always
environment:
- PORT=3000
- NO_DOTENV=1
- DATABASE_USERNAME=sshsync
- DATABASE_PASSWORD=sshsync
- DATABASE_NAME=sshsync
- DATABASE_HOST=ssh-sync-db:5432
logging:
driver: json-file
options:
max-size: 10m
ports:
- '3000:3000'
image: fd49561087a8563fece3be7eff59f6ff728c3e749fbd4ebfaee96a6ee3982b7d
container_name: ssh-sync-server
ssh-sync-db:
image: therealpaulgg/ssh-sync-db:latest
container_name: ssh-sync-db
environment:
- POSTGRES_USER=sshsync
- POSTGRES_PASSWORD=sshsync
- POSTGRES_DB=sshsync
restart: always
ssh-sync:
image: 46204e8109ce
container_name: ssh-sync
stdin_open: true # Allows Docker container to keep STDIN open
tty: true # Allocates a pseudo-TTY
ssh-sync-2:
image: 46204e8109ce
container_name: ssh-sync-2
stdin_open: true # Allows Docker container to keep STDIN open
tty: true # Allocates a pseudo-TTY
ssh-sync-3:
image: 46204e8109ce
container_name: ssh-sync-3
stdin_open: true # Allows Docker container to keep STDIN open
tty: true # Allocates a pseudo-TTY
33 changes: 17 additions & 16 deletions pkg/web/live/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ type Something struct {
}

type SafeChallengeResponseDict struct {
mux sync.Mutex
dict map[string]Something
mux sync.Mutex
dict map[string]Something
}

// Now, whenever you access ChallengeResponseDict, use the mutex to synchronize access.
// For example, when writing to the map:
func (c *SafeChallengeResponseDict) WriteChallenge(challengePhrase string, data Something) {
c.mux.Lock() // lock before accessing the map
c.dict[challengePhrase] = data
c.mux.Unlock() // unlock after accessing the map
c.mux.Lock() // lock before accessing the map
c.dict[challengePhrase] = data
c.mux.Unlock() // unlock after accessing the map
}

// And when reading or deleting from the map:
func (c* SafeChallengeResponseDict) ReadChallenge(challengePhrase string) (Something, bool) {
c.mux.Lock() // lock before accessing the map
data, exists := c.dict[challengePhrase]
c.mux.Unlock() // unlock after accessing the map
return data, exists
func (c *SafeChallengeResponseDict) ReadChallenge(challengePhrase string) (Something, bool) {
c.mux.Lock() // lock before accessing the map
data, exists := c.dict[challengePhrase]
c.mux.Unlock() // unlock after accessing the map
return data, exists
}

var ChallengeResponseChannel = make(chan ChallengeResponse)
var ChallengeResponseDict = SafeChallengeResponseDict{
dict: make(map[string]Something),
dict: make(map[string]Something),
}

func MachineChallengeResponse(i *do.Injector, r *http.Request, w http.ResponseWriter) error {
Expand Down Expand Up @@ -208,19 +208,19 @@ func NewMachineChallengeHandler(i *do.Injector, r *http.Request, w http.Response
timer := time.NewTimer(30 * time.Second)
go func() {
var challengeAcceptedChan chan bool

// Lock before accessing ChallengeResponseDict
ChallengeResponseDict.mux.Lock()
if item, exists := ChallengeResponseDict.dict[challengePhrase]; exists {
challengeAcceptedChan = item.ChallengeAccepted
}
ChallengeResponseDict.mux.Unlock()

// If the channel does not exist, return to avoid a nil channel operation
if challengeAcceptedChan == nil {
return
}

for {
select {
case <-timer.C:
Expand Down Expand Up @@ -261,8 +261,9 @@ func NewMachineChallengeHandler(i *do.Injector, r *http.Request, w http.Response
log.Err(err).Msg("Error reading client message")
return
}
ChallengeResponseDict[challengePhrase].ChallengerChannel <- pubkey.Data.PublicKey
encryptedMasterKey := <-ChallengeResponseDict[challengePhrase].ResponderChannel

cha.ChallengerChannel <- pubkey.Data.PublicKey
encryptedMasterKey := <-cha.ResponderChannel
machine.PublicKey = pubkey.Data.PublicKey
if _, err = machineRepo.CreateMachine(machine); err != nil {
log.Err(err).Msg("Error creating machine")
Expand Down

0 comments on commit b36159e

Please sign in to comment.