storage.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. GNU GENERAL PUBLIC LICENSE
  3. Version 3, 29 June 2007
  4. kyoketsu, a Client-To-Client Network Enumeration System
  5. Copyright (C) 2024 Russell Hrubesky, ChiralWorks Software LLC
  6. Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
  7. Everyone is permitted to copy and distribute verbatim copies
  8. of this license document, but changing it is not allowed.
  9. This program is free software: you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation, either version 3 of the License,
  12. or (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. See the GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package kyoketsu
  21. import (
  22. "context"
  23. "fmt"
  24. "time"
  25. "go.mongodb.org/mongo-driver/mongo"
  26. "go.mongodb.org/mongo-driver/mongo/options"
  27. )
  28. type TopologyDatabaseIO interface {
  29. /*
  30. This interface defines the Input and output methods that will be necessary
  31. for an appropriate implementation of the data storage that the distributed system will use.
  32. When I get around to implementing the client-to-client format of this, it could be anything.
  33. */
  34. AddHostToDb(*Host) error // Add a host to the hosts table
  35. UpdateHostEntry(string, *Host) error //Update a host entry, indexing by its ip address
  36. RemoveHostEntry(string) error // Remove a host from the database
  37. }
  38. type MongoClient struct {
  39. conn *mongo.Client
  40. }
  41. func NewMongoClient(host string, port int) *MongoClient {
  42. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  43. defer cancel()
  44. client, err := mongo.Connect(ctx, options.Client().ApplyURI(fmt.Sprintf("mongodb://%s:%v", host, port)))
  45. defer func() {
  46. if err = client.Disconnect(ctx); err != nil {
  47. panic(err)
  48. }
  49. }()
  50. return &MongoClient{conn: client}
  51. }
  52. func (m *MongoClient) addDocument(id string, data interface{}) error {
  53. return nil
  54. }
  55. func (m *MongoClient) AddHostToDb(host *Host) error {
  56. return nil
  57. }
  58. func (m *MongoClient) UpdateHostEntry(id string, host *Host) error {
  59. return nil
  60. }
  61. func (m *MongoClient) RemoveHostEntry(id string) error {
  62. return nil
  63. }