Browse Source

making changes to grpc comms vars

afeiszli 4 years ago
parent
commit
be0d274ca6

+ 0 - 1
config/config.go

@@ -55,7 +55,6 @@ type WG struct {
   GRPCWGInterface  string `yaml:"grpciface"`
   GRPCWGAddress  string `yaml:"grpcaddr"`
   GRPCWGAddressRange  string `yaml:"grpcaddrrange"`
-  GRPCWGEndpoint  string `yaml:"grpcendpoint"`
   GRPCWGPort  string  `yaml:"grpcport"`
   GRPCWGPubKey  string  `yaml:"pubkey"`
   GRPCWGPrivKey  string  `yaml:"privkey"`

BIN
controllers/.networkHttpController.go.swp


+ 8 - 12
controllers/intClientHttpController.go

@@ -138,17 +138,13 @@ func RegisterIntClient(client models.IntClient) (models.IntClient, error) {
 		client.Address = newAddress
 	}
         if client.Network == "" { client.Network = "comms" }
-	server, err := serverctl.GetServerWGConf()
-	if err != nil {
-		return client, err
-	}
-  gcfg := servercfg.GetConfig()
-  client.ServerWGEndpoint = server.ServerWGEndpoint
-  client.ServerAPIEndpoint = gcfg.APIHost + ":" + gcfg.APIPort
-	client.ServerAddress = server.ServerAddress
-	client.ServerPort = server.ServerPort
-	client.ServerGRPCPort = gcfg.GRPCPort
-	client.ServerKey = server.ServerKey
+
+	wgconfig := servercfg.GetWGConfig()
+        client.ServerPublicEndpoint = servercfg.GetAPIHost()
+        client.ServerAPIPort = servercfg.GetAPIPort()
+        client.ServerPrivateAddress = wgconfig.GRPCWGAddress
+        client.ServerWGPort = wgconfig.GRPCWGPort
+        client.ServerGRPCPort = servercfg.GetGRPCPort()
 
         if client.ClientID == "" {
                 clientid := StringWithCharset(7, charset)
@@ -160,7 +156,7 @@ func RegisterIntClient(client models.IntClient) (models.IntClient, error) {
 	collection := mongoconn.Client.Database("netmaker").Collection("intclients")
 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 	// insert our network into the network table
-	_, err = collection.InsertOne(ctx, client)
+	_, err := collection.InsertOne(ctx, client)
 	defer cancel()
 
 	if err != nil {

+ 2 - 2
controllers/nodeGrpcController.go

@@ -73,7 +73,7 @@ func (s *NodeServiceServer) ReadNode(ctx context.Context, req *nodepb.ReadNodeRe
 	}
 	return response, nil
 }
-
+/*
 func (s *NodeServiceServer) GetConn(ctx context.Context, data *nodepb.Client) (*nodepb.Client, error) {
         // Get the protobuf node type from the protobuf request type
         // Essentially doing req.Node to access the struct with a nil check
@@ -124,7 +124,7 @@ func (s *NodeServiceServer) GetConn(ctx context.Context, data *nodepb.Client) (*
 
         return response, nil
 }
-
+*/
 func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNodeReq) (*nodepb.CreateNodeRes, error) {
 	// Get the protobuf node type from the protobuf request type
 	// Essentially doing req.Node to access the struct with a nil check

BIN
docs/_build/doctrees/environment.pickle


BIN
docs/_build/doctrees/support.doctree


+ 6 - 0
docs/_build/html/_sources/support.rst.txt

@@ -21,6 +21,12 @@ How do I install the Netclient on X?
 
 As per the above, there are many unsupported operating systems. You are still welcome to try, it is just an executable binary file after all. If the system is unix-based and has kernel WireGuard installed, netclient may very well mesh the device into the network. However, the service likely will encounter problems retrieving updates.
 
+Why MongoDB? SQL is better and smaller.
+----------------------------------------
+
+We are in a phase of rapid iteration. Every week the database schema changes. MongoDB makes our development process much more flexible. That said, we agree! SQL will be better for production, and indeed, we plan to switch over to SQL before v1.0, so please be patient with the resource consumption of MongoDB for the time being; it is helping to support a rapid pace of development. 
+
+
 Is Netmaker a VPN like NordNPN?
 --------------------------------
 

File diff suppressed because it is too large
+ 0 - 0
docs/_build/html/searchindex.js


+ 8 - 0
docs/_build/html/support.html

@@ -604,6 +604,8 @@
         </li>
         <li class="md-nav__item"><a href="#how-do-i-install-the-netclient-on-x" class="md-nav__link">How do I install the Netclient on X?</a>
         </li>
+        <li class="md-nav__item"><a href="#why-mongodb-sql-is-better-and-smaller" class="md-nav__link">Why MongoDB? SQL is better and smaller.</a>
+        </li>
         <li class="md-nav__item"><a href="#is-netmaker-a-vpn-like-nordnpn" class="md-nav__link">Is Netmaker a VPN like NordNPN?</a>
         </li>
         <li class="md-nav__item"><a href="#do-you-offer-any-paid-support" class="md-nav__link">Do you offer any paid support?</a>
@@ -756,6 +758,8 @@
         </li>
         <li class="md-nav__item"><a href="#how-do-i-install-the-netclient-on-x" class="md-nav__link">How do I install the Netclient on X?</a>
         </li>
+        <li class="md-nav__item"><a href="#why-mongodb-sql-is-better-and-smaller" class="md-nav__link">Why MongoDB? SQL is better and smaller.</a>
+        </li>
         <li class="md-nav__item"><a href="#is-netmaker-a-vpn-like-nordnpn" class="md-nav__link">Is Netmaker a VPN like NordNPN?</a>
         </li>
         <li class="md-nav__item"><a href="#do-you-offer-any-paid-support" class="md-nav__link">Do you offer any paid support?</a>
@@ -801,6 +805,10 @@
 <p>As per the above, there are many unsupported operating systems. You are still welcome to try, it is just an executable binary file after all. If the system is unix-based and has kernel WireGuard installed, netclient may very well mesh the device into the network. However, the service likely will encounter problems retrieving updates.</p>
 
 
+<h3 id="why-mongodb-sql-is-better-and-smaller">Why MongoDB? SQL is better and smaller.<a class="headerlink" href="#why-mongodb-sql-is-better-and-smaller" title="Permalink to this headline">¶</a></h3>
+<p>We are in a phase of rapid iteration. Every week the database schema changes. MongoDB makes our development process much more flexible. That said, we agree! SQL will be better for production, and indeed, we plan to switch over to SQL before v1.0, so please be patient with the resource consumption of MongoDB for the time being; it is helping to support a rapid pace of development.</p>
+
+
 <h3 id="is-netmaker-a-vpn-like-nordnpn">Is Netmaker a VPN like NordNPN?<a class="headerlink" href="#is-netmaker-a-vpn-like-nordnpn" title="Permalink to this headline">¶</a></h3>
 <p>No. Netmaker makes Virtual Networks, which are technically VPNs, but different. It’s more like a corporate VPN, or a VPC (if you’re familiar with AWS).</p>
 <p>If you’re looking to achieve self-hosted web browsing, with functionality similar to NordVPN, ExpressVPN, Surfshark, Tunnelbear, or Private Internet Access, this is probably not the project for you. Technically, you can accomplish this with Netmaker, but it would be a little like using a all-terrain vehicle for stock car racing.</p>

+ 4 - 4
models/intclient.go

@@ -8,10 +8,10 @@ type IntClient struct {
 	Address        string             `json:"address" bson:"address"`
 	Address6       string             `json:"address6" bson:"address6"`
 	Network        string             `json:"network" bson:"network"`
-	ServerWGEndpoint  string          `json:"serverwgendpoint" bson:"serverwgendpoint"`
-	ServerAPIEndpoint  string         `json:"serverapiendpoint" bson:"serverapiendpoint"`
-	ServerAddress  string             `json:"serveraddress" bson:"serveraddress"`
-	ServerPort     string             `json:"serverport" bson:"serverport"`
+	ServerPublicEndpoint  string `json:"serverwgendpoint" bson:"serverwgendpoint"`
+	ServerAPIPort  string      `json:"serverapiendpoint" bson:"serverapiendpoint"`
+	ServerPrivateAddress  string       `json:"serveraddress" bson:"serveraddress"`
+	ServerWGPort     string             `json:"serverport" bson:"serverport"`
 	ServerGRPCPort     string             `json:"serverport" bson:"serverport"`
 	ServerKey      string             `json:"serverkey" bson:"serverkey"`
 	IsServer       string             `json:"isserver" bson:"isserver"`

+ 30 - 24
netclient/config/config.go

@@ -240,8 +240,14 @@ func ModGlobalConfig(cfg models.IntClient) error{
                 }
                 modconfig = *useconfig
         }
-        if cfg.ServerPort != ""{
-                modconfig.Client.ServerPort = cfg.ServerPort
+        if cfg.ServerWGPort != ""{
+                modconfig.Client.ServerWGPort = cfg.ServerWGPort
+        }
+        if cfg.ServerGRPCPort != ""{
+                modconfig.Client.ServerGRPCPort = cfg.ServerGRPCPort
+        }
+        if cfg.ServerAPIPort != ""{
+                modconfig.Client.ServerAPIPort = cfg.ServerAPIPort
         }
         if cfg.PublicKey != ""{
                 modconfig.Client.PublicKey = cfg.PublicKey
@@ -249,11 +255,11 @@ func ModGlobalConfig(cfg models.IntClient) error{
         if cfg.PrivateKey != ""{
                 modconfig.Client.PrivateKey = cfg.PrivateKey
         }
-        if cfg.ServerWGEndpoint != ""{
-                modconfig.Client.ServerWGEndpoint = cfg.ServerWGEndpoint
+        if cfg.ServerPublicEndpoint != ""{
+                modconfig.Client.ServerPublicEndpoint = cfg.ServerPublicEndpoint
         }
-        if cfg.ServerAddress != ""{
-                modconfig.Client.ServerAddress = cfg.ServerAddress
+        if cfg.ServerPrivateAddress != ""{
+                modconfig.Client.ServerPrivateAddress = cfg.ServerPrivateAddress
         }
 	if cfg.Address != ""{
                 modconfig.Client.Address = cfg.Address
@@ -363,12 +369,12 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, error){
                 }
                 token := string(tokenbytes)
                 tokenvals := strings.Split(token, "|")
-                cfg.Server.GRPCAddress = tokenvals[0]
-                cfg.Server.APIAddress = tokenvals[1]
-                cfg.Network = tokenvals[2]
-                cfg.Node.Network = tokenvals[2]
-                cfg.Server.AccessKey = tokenvals[3]
-                cfg.Node.LocalRange = tokenvals[4]
+                cfg.Server.GRPCAddress = tokenvals[1]
+                cfg.Server.APIAddress = tokenvals[2]
+                cfg.Network = tokenvals[3]
+                cfg.Node.Network = tokenvals[4]
+                cfg.Server.AccessKey = tokenvals[5]
+                cfg.Node.LocalRange = tokenvals[6]
 
 		if c.String("grpcserver") != "" {
 			cfg.Server.GRPCAddress = c.String("grpcserver")
@@ -429,21 +435,21 @@ func GetCLIConfigRegister(c *cli.Context) (GlobalConfig, error){
                 }
                 token := string(tokenbytes)
                 tokenvals := strings.Split(token, "|")
-                cfg.Client.ServerAddress = tokenvals[0]
-                cfg.Client.ServerAPIEndpoint = tokenvals[1]
-		servervals := strings.Split(tokenvals[1], ":")
-		wgvals := strings.Split(tokenvals[0], ":")
-		cfg.Client.ServerWGEndpoint = servervals[0]
-                cfg.Client.ServerAddress = wgvals[0]
-                cfg.Client.ServerPort = wgvals[1]
+		grpcvals := strings.Split(tokenvals[1],":")
+		apivals := strings.Split(tokenvals[2], ":")
+		cfg.Client.ServerWGPort = tokenvals[0]
+                cfg.Client.ServerPrivateAddress = grpcvals[0]
+                cfg.Client.ServerGRPCPort = grpcvals[1]
+                cfg.Client.ServerPublicEndpoint = apivals[0]
+                cfg.Client.ServerAPIPort = apivals[1]
 
-		cfg.Client.ServerKey = tokenvals[3]
+		cfg.Client.ServerKey = tokenvals[4]
 
                 if c.String("grpcserver") != "" {
-                        cfg.Client.ServerAddress = c.String("grpcserver")
+                        cfg.Client.ServerPrivateAddress = c.String("grpcserver")
                 }
                 if c.String("apiserver") != "" {
-                        cfg.Client.ServerAPIEndpoint = c.String("apiserver")
+                        cfg.Client.ServerPublicEndpoint = c.String("apiserver")
                 }
                 if c.String("key") != "" {
                         cfg.Client.ServerKey = c.String("key")
@@ -452,8 +458,8 @@ func GetCLIConfigRegister(c *cli.Context) (GlobalConfig, error){
                         cfg.Client.Network = c.String("network")
                 }
         } else {
-                cfg.Client.ServerAddress = c.String("grpcserver")
-                cfg.Client.ServerWGEndpoint = c.String("apiserver")
+                cfg.Client.ServerPrivateAddress = c.String("grpcserver")
+                cfg.Client.ServerPublicEndpoint = c.String("apiserver")
                 cfg.Client.ServerKey = c.String("key")
                 cfg.Client.Network = c.String("network")
         }

+ 7 - 7
netclient/functions/register.go

@@ -41,8 +41,10 @@ func Register(cfg config.GlobalConfig) error {
         }
 	jsonbytes := []byte(jsonstring)
 	body := bytes.NewBuffer(jsonbytes)
-	log.Println("registering to http://"+cfg.Client.ServerAPIEndpoint+"/api/client/register")
-	res, err := http.Post("http://"+cfg.Client.ServerAPIEndpoint+"/api/intclient/register","application/json",body)
+	publicaddress := cfg.Client.ServerPublicEndpoint + ":" + cfg.Client.ServerAPIPort
+
+	log.Println("registering to http://"+publicaddress+"/api/client/register")
+	res, err := http.Post("http://"+publicaddress+"/api/intclient/register","application/json",body)
         if err != nil {
                 return err
         }
@@ -60,9 +62,6 @@ func Register(cfg config.GlobalConfig) error {
         if err != nil {
                 return err
         }
-	if wgclient.ServerWGEndpoint == "" {
-		wgclient.ServerWGEndpoint = cfg.Client.ServerWGEndpoint
-	}
         spew.Dump(wgclient)
 	err = wireguard.InitGRPCWireguard(wgclient)
         if err != nil {
@@ -74,13 +73,14 @@ func Register(cfg config.GlobalConfig) error {
 
 func Unregister(cfg config.GlobalConfig) error {
 	client := &http.Client{ Timeout: 7 * time.Second,}
-	req, err := http.NewRequest("DELETE", "http://"+cfg.Client.ServerAPIEndpoint+"/api/intclient/"+cfg.Client.ClientID, nil)
+	publicaddress := cfg.Client.ServerPublicEndpoint + ":" + cfg.Client.ServerAPIPort
+	req, err := http.NewRequest("DELETE", "http://"+publicaddress+"/api/intclient/"+cfg.Client.ClientID, nil)
 	if err != nil {
                 log.Println(err)
         } else {
 		res, err := client.Do(req)
 		if res == nil {
-	                err = errors.New("server not reachable at " + "http://"+cfg.Client.ServerAPIEndpoint+"/api/intclient/"+cfg.Client.ClientID)
+	                err = errors.New("server not reachable at " + "http://"+publicaddress+"/api/intclient/"+cfg.Client.ClientID)
 			log.Println(err)
 		} else if res.StatusCode != http.StatusOK {
 			err = errors.New("request to server failed: " + res.Status)

+ 1 - 1
netclient/main.go

@@ -191,7 +191,7 @@ func main() {
                 if err != nil {
                         return err
                 }
-                if cfg.Client.ServerAddress == "" {
+                if cfg.Client.ServerPrivateAddress == "" {
                         err = errors.New("No server address provided.")
                         return err
                 }

+ 4 - 4
netclient/wireguard/kernel.go

@@ -33,7 +33,7 @@ func InitGRPCWireguard(client models.IntClient) error {
         if err !=  nil {
                 return err
         }
-	serverport, err := strconv.Atoi(client.ServerPort)
+	serverport, err := strconv.Atoi(client.ServerWGPort)
         if err !=  nil {
                 return err
         }
@@ -87,16 +87,16 @@ func InitGRPCWireguard(client models.IntClient) error {
         }
 	var peers []wgtypes.PeerConfig
         var peeraddr = net.IPNet{
-                 IP: net.ParseIP(client.ServerAddress),
+                 IP: net.ParseIP(client.ServerPrivateAddress),
                  Mask: net.CIDRMask(32, 32),
         }
 	var allowedips []net.IPNet
         allowedips = append(allowedips, peeraddr)
-	net.ParseIP(client.ServerWGEndpoint)
+	net.ParseIP(client.ServerPublicEndpoint)
 	peer := wgtypes.PeerConfig{
                PublicKey: serverkey,
                Endpoint: &net.UDPAddr{
-                         IP:   net.ParseIP(client.ServerWGEndpoint),
+                         IP:   net.ParseIP(client.ServerPublicEndpoint),
                          Port: serverport,
                },
                ReplaceAllowedIPs: true,

+ 2 - 2
servercfg/serverconf.go

@@ -57,8 +57,8 @@ func GetWGConfig() config.WG{
 	cfg.GRPCWGInterface = GetGRPCWGInterface()
 	cfg.GRPCWGAddress = GetGRPCWGAddress()
 	cfg.GRPCWGPort = GetGRPCWGPort()
-	cfg.GRPCWGEndpoint = GetGRPCHost()
-
+	cfg.GRPCWGPubKey =  GetGRPCWGPubKey()
+	cfg.GRPCWGPrivKey =  GetGRPCWGPrivKey()
 	return cfg
 }
 

+ 5 - 3
serverctl/wireguard.go

@@ -61,9 +61,11 @@ func InitServerWireGuard() error {
 	var client models.IntClient
 	client.PrivateKey = wgconfig.GRPCWGPrivKey
 	client.PublicKey = wgconfig.GRPCWGPubKey
-	client.ServerWGEndpoint = wgconfig.GRPCWGEndpoint
-	client.ServerAddress = wgconfig.GRPCWGAddress
-	client.ServerPort = wgconfig.GRPCWGPort
+	client.ServerPublicEndpoint = servercfg.GetAPIHost()
+	client.ServerAPIPort = servercfg.GetAPIPort()
+	client.ServerPrivateAddress = wgconfig.GRPCWGAddress
+	client.ServerWGPort = wgconfig.GRPCWGPort
+	client.ServerGRPCPort = servercfg.GetGRPCPort()
 	client.Address = wgconfig.GRPCWGAddress
 	client.IsServer = "yes"
 	client.Network = "comms"

Some files were not shown because too many files changed in this diff