Skip to content

Commit

Permalink
some mongodb changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyagara committed Nov 5, 2024
1 parent bfe2e0f commit a1afdcf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
9 changes: 6 additions & 3 deletions hagelslag.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ import (
"github.com/rs/zerolog/log"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/writeconcern"
)

var (
ErrMaximumResponseLength = errors.New("maximum response length exceeded")
)

type Hagelslag struct {
// Scanner being used (default: http)
Scanner Scanner
// IP address to start scanning from
StartingIP string
// Number of workers to use (default: number of threads)
Expand All @@ -31,8 +34,6 @@ type Hagelslag struct {
MaxTasks int
// Tasks per thread (default: 512)
TasksPerThread int
// Scanner being used (default: http)
Scanner Scanner
}

type Scanner interface {
Expand Down Expand Up @@ -81,7 +82,9 @@ func NewHagelslag() (Hagelslag, error) {
func (h Hagelslag) worker(ips <-chan string, wg *sync.WaitGroup) {
defer wg.Done()

options := options.Client().ApplyURI("mongodb://localhost:27017")
options := options.Client().
ApplyURI("mongodb://localhost:27017").
SetWriteConcern(&writeconcern.WriteConcern{})

client, err := mongo.Connect(context.TODO(), options)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func (s HTTP) Scan(ip string, conn net.Conn) ([]byte, int64, error) {
}

func (s HTTP) Save(ip string, latency int64, data []byte, collection *mongo.Collection) error {
document := bson.D{
{Key: "_id", Value: ip},
{Key: "latency", Value: latency},
{Key: "data", Value: *(*string)(unsafe.Pointer(&data))},
document := bson.M{
"_id": ip,
"latency": latency,
"data": *(*string)(unsafe.Pointer(&data)),
}

filter := bson.M{"_id": ip}
Expand Down
8 changes: 4 additions & 4 deletions veloren.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ func (s Veloren) Save(ip string, latency int64, data []byte, collection *mongo.C
BattleMode: data[24],
}

document := bson.D{
{Key: "_id", Value: ip},
{Key: "latency", Value: latency},
{Key: "data", Value: info},
document := bson.M{
"_id": ip,
"latency": latency,
"data": info,
}

filter := bson.M{"_id": ip}
Expand Down

0 comments on commit a1afdcf

Please sign in to comment.