use correct connections
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m48s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m48s
This commit is contained in:
29
rpc-pool.go
29
rpc-pool.go
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@@ -30,31 +29,18 @@ type RemoteGrain struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRemoteGrain(id CartId, address string) *RemoteGrain {
|
func NewRemoteGrain(id CartId, address string) *RemoteGrain {
|
||||||
|
client, err := CartDial(address)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return &RemoteGrain{
|
return &RemoteGrain{
|
||||||
Id: id,
|
Id: id,
|
||||||
Address: address,
|
Address: address,
|
||||||
|
CartClient: client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *RemoteGrain) Connect() error {
|
|
||||||
if g == nil {
|
|
||||||
return fmt.Errorf("grain is deleted")
|
|
||||||
}
|
|
||||||
if g.connection == nil {
|
|
||||||
addr := g.Address
|
|
||||||
if !strings.Contains(addr, ":") {
|
|
||||||
addr = fmt.Sprintf("%s:1337", addr)
|
|
||||||
}
|
|
||||||
client, err := net.Dial("tcp", addr)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
g.Conn = client
|
|
||||||
g.PacketQueue = NewPacketQueue(client)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *RemoteGrain) HandleMessage(message *Message, isReplay bool) ([]byte, error) {
|
func (g *RemoteGrain) HandleMessage(message *Message, isReplay bool) ([]byte, error) {
|
||||||
|
|
||||||
data, err := GetData(message.Write)
|
data, err := GetData(message.Write)
|
||||||
@@ -92,7 +78,6 @@ func (p *RemoteGrainPool) findRemoteGrain(id CartId) *RemoteGrain {
|
|||||||
if !ok || grain == nil {
|
if !ok || grain == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
grain.Connect()
|
|
||||||
return grain
|
return grain
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,10 +85,10 @@ func (p *RemoteGrainPool) findOrCreateGrain(id CartId) *RemoteGrain {
|
|||||||
grain := p.findRemoteGrain(id)
|
grain := p.findRemoteGrain(id)
|
||||||
if grain == nil {
|
if grain == nil {
|
||||||
grain = NewRemoteGrain(id, p.Host)
|
grain = NewRemoteGrain(id, p.Host)
|
||||||
|
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
p.grains[id] = grain
|
p.grains[id] = grain
|
||||||
p.mu.Unlock()
|
p.mu.Unlock()
|
||||||
grain.Connect()
|
|
||||||
}
|
}
|
||||||
return grain
|
return grain
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user