Commit f0a3d15c authored by opelhoward's avatar opelhoward
Browse files

ga ngerti lg

parent ae2fa120
......@@ -27,8 +27,8 @@
<file leaf-file-name="sconnectionhandler.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/sconnectionhandler.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="5720" max-vertical-offset="8772">
<caret line="346" column="86" selection-start-line="346" selection-start-column="86" selection-end-line="346" selection-end-column="86" />
<state vertical-scroll-proportion="0.0" vertical-offset="161" max-vertical-offset="8772">
<caret line="21" column="49" selection-start-line="21" selection-start-column="49" selection-end-line="21" selection-end-column="49" />
<folding>
<element signature="e#21#32#0" expanded="true" />
</folding>
......@@ -36,6 +36,16 @@
</provider>
</entry>
</file>
<file leaf-file-name="inventory.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/inventory.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.72613066" vertical-offset="0" max-vertical-offset="408">
<caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="sclient.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/sclient.py">
<provider selected="true" editor-type-id="text-editor">
......@@ -48,11 +58,11 @@
</provider>
</entry>
</file>
<file leaf-file-name="tradebox.py" pinned="false" current-in-tab="true">
<file leaf-file-name="tradebox.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tradebox.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="1.0552764" vertical-offset="566" max-vertical-offset="1275">
<caret line="58" column="13" selection-start-line="58" selection-start-column="13" selection-end-line="58" selection-end-column="13" />
<state vertical-scroll-proportion="0.0" vertical-offset="877" max-vertical-offset="1275">
<caret line="48" column="22" selection-start-line="48" selection-start-column="22" selection-end-line="48" selection-end-column="22" />
<folding>
<element signature="e#22#53#0" expanded="true" />
</folding>
......@@ -63,9 +73,11 @@
<file leaf-file-name="market.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/market.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="554" max-vertical-offset="1020">
<caret line="55" column="15" selection-start-line="55" selection-start-column="15" selection-end-line="55" selection-end-column="15" />
<folding />
<state vertical-scroll-proportion="0.0" vertical-offset="452" max-vertical-offset="1122">
<caret line="46" column="20" selection-start-line="46" selection-start-column="20" selection-end-line="46" selection-end-column="20" />
<folding>
<element signature="e#22#53#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
......@@ -73,7 +85,7 @@
<file leaf-file-name="user.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/user.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="605" max-vertical-offset="1207">
<state vertical-scroll-proportion="0.0" vertical-offset="554" max-vertical-offset="1207">
<caret line="63" column="32" selection-start-line="63" selection-start-column="32" selection-end-line="63" selection-end-column="32" />
<folding />
</state>
......@@ -86,12 +98,12 @@
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/map.py" />
<option value="$PROJECT_DIR$/inventory.py" />
<option value="$PROJECT_DIR$/sclient.py" />
<option value="$PROJECT_DIR$/tradebox.py" />
<option value="$PROJECT_DIR$/user.py" />
<option value="$PROJECT_DIR$/sconnectionhandler.py" />
<option value="$PROJECT_DIR$/market.py" />
<option value="$PROJECT_DIR$/sconnectionhandler.py" />
<option value="$PROJECT_DIR$/inventory.py" />
</list>
</option>
</component>
......@@ -349,7 +361,7 @@
<window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Python Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32913387" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32913387" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="11" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
......@@ -418,7 +430,9 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="714" max-vertical-offset="884">
<caret line="43" column="20" selection-start-line="43" selection-start-column="20" selection-end-line="43" selection-end-column="20" />
<folding />
<folding>
<element signature="e#22#53#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
......@@ -464,7 +478,9 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="714" max-vertical-offset="884">
<caret line="43" column="20" selection-start-line="43" selection-start-column="20" selection-end-line="43" selection-end-column="20" />
<folding />
<folding>
<element signature="e#22#53#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
......@@ -631,13 +647,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/inventory.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.40201005" vertical-offset="10" max-vertical-offset="408">
<caret line="10" column="0" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/sserver.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="1.022613" vertical-offset="409" max-vertical-offset="1921">
......@@ -652,16 +661,24 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/sconnectionhandler.py">
<entry file="file://$PROJECT_DIR$/tradebox.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="5720" max-vertical-offset="8772">
<caret line="346" column="86" selection-start-line="346" selection-start-column="86" selection-end-line="346" selection-end-column="86" />
<state vertical-scroll-proportion="0.0" vertical-offset="872" max-vertical-offset="1275">
<caret line="48" column="22" selection-start-line="48" selection-start-column="22" selection-end-line="48" selection-end-column="22" />
<folding>
<element signature="e#21#32#0" expanded="true" />
<element signature="e#22#53#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/user.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="605" max-vertical-offset="1207">
<caret line="63" column="32" selection-start-line="63" selection-start-column="32" selection-end-line="63" selection-end-column="32" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/sclient.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="120" max-vertical-offset="2125">
......@@ -672,29 +689,31 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/user.py">
<entry file="file://$PROJECT_DIR$/market.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="605" max-vertical-offset="1207">
<caret line="63" column="32" selection-start-line="63" selection-start-column="32" selection-end-line="63" selection-end-column="32" />
<folding />
<state vertical-scroll-proportion="0.0" vertical-offset="452" max-vertical-offset="1122">
<caret line="46" column="20" selection-start-line="46" selection-start-column="20" selection-end-line="46" selection-end-column="20" />
<folding>
<element signature="e#22#53#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/market.py">
<entry file="file://$PROJECT_DIR$/sconnectionhandler.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="554" max-vertical-offset="1020">
<caret line="55" column="15" selection-start-line="55" selection-start-column="15" selection-end-line="55" selection-end-column="15" />
<folding />
<state vertical-scroll-proportion="0.0" vertical-offset="161" max-vertical-offset="8772">
<caret line="21" column="49" selection-start-line="21" selection-start-column="49" selection-end-line="21" selection-end-column="49" />
<folding>
<element signature="e#21#32#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tradebox.py">
<entry file="file://$PROJECT_DIR$/inventory.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="1.0552764" vertical-offset="566" max-vertical-offset="1275">
<caret line="58" column="13" selection-start-line="58" selection-start-column="13" selection-end-line="58" selection-end-column="13" />
<folding>
<element signature="e#22#53#0" expanded="true" />
</folding>
<state vertical-scroll-proportion="0.72613066" vertical-offset="0" max-vertical-offset="408">
<caret line="17" column="58" selection-start-line="17" selection-start-column="58" selection-end-line="17" selection-end-column="58" />
<folding />
</state>
</provider>
</entry>
......
__author__ = 'Willy'
from pymongo import MongoClient
from inventory import Inventory;
import time
class OfferMarket:
......@@ -18,7 +18,7 @@ class OfferMarket:
class Market:
time = 0
__time = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
__market = MongoClient('localhost', 27017)['sister']\
.get_collection("market")
......@@ -40,6 +40,7 @@ class Market:
'ip': ip, 'port': port})
@staticmethod
def clear(item_id):
Market.__time[item_id] = time.time()
Market.__market.delete_many({'offered_item': item_id})
@staticmethod
......@@ -53,4 +54,8 @@ class Market:
@staticmethod
def exist(token):
return Market.__market.find_one_and_replace({'offer_token': token}, {'availability': False}) != None
\ No newline at end of file
return Market.__market.find_one_and_replace({'offer_token': token}, {'availability': False}) != None
@staticmethod
def dirty(item):
return time.time() - Market.__time[item] > 30
\ No newline at end of file
......@@ -3,7 +3,6 @@ import time
import json
import socket as Socket
import select
import codecs
from user import User
from map import Map
from tradebox import Tradebox
......@@ -16,10 +15,10 @@ class ConnectionHandler:
TRACKER_IP = '167.205.32.46'
TRACKER_PORT = 8000
BUFFER_SIZE = 4096
READ_TIMEOUT = 3 # buat ngehandle json yang belum selesai kekirim
CONNECTION_TIMEOUT = 5 # dalam detikkalo client gak ngirim ping apa2 ke server, bisa dianggap timeout
def __init__(self,conn,addr,server_instance):
self._conn = conn #client socket
self._addr = addr #client address
......@@ -257,24 +256,25 @@ class ConnectionHandler:
# invoke sendfind
def handle_sendfind(self,token,item):
#tambahin server abusive
Market.clear(item)
offer_list = []
thread_list = []
# untuk setiap server lain
for other_server in self._server._server_list:
host = other_server.get('ip')
port = int(other_server.get('port'))
if (not ((host == self._server.__class__.TRACKER_IP) and (port == self._server.__class__.TRACKER_PORT))):
thr = FindOfferThread(host,port,item)
thread_list.append(thr)
thr.start()
for thr in thread_list:
thr.join()
for thr in thread_list:
# print(thr.get_result())
offer_list.extend(thr.get_result())
if Market.dirty(item):
Market.clear(item)
for other_server in self._server._server_list:
host = other_server.get('ip')
port = int(other_server.get('port'))
if (not ((host == self._server.__class__.TRACKER_IP) and (port == self._server.__class__.TRACKER_PORT))):
thr = FindOfferThread(host,port,item)
thread_list.append(thr)
thr.start()
for thr in thread_list:
thr.join()
for thr in thread_list:
# print(thr.get_result())
offer_list.extend(thr.get_result())
offer_list = Market.get_offers(item)
my_offers = Tradebox.get_offers(token)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment